首先感谢这位博客主人,我从他这边得到了线索
https://frankco.iteye.com/blog/1709059
我是最近在解析某个csv文件是,返现里面的日期字段全部是 数字-英文月份-数字年 例如:05-Mar-2019 ,而我入库存储date类型必须在java方法中对它进行转化,其实我们可以将它split之后,对Mar做个枚举类,来获取对应的 03,但是,谁让我懒呢,就想着有没有一步到位的方法;
好,废话结束,直接贴代码:
public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMMM-yyyy", Locale.ENGLISH);
try {
Date date2 = sdf.parse("05-Mar-2019");
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
System.out.println(simpleDateFormat.format(date2));
sdf.format(new Date());
} catch (ParseException e) {
}
}
上面运行完毕会打印出:
2019-03-05