如何将字符串转换为日期格式dd/MM/yyyy [英] how to convert string to dateformat dd/MM/yyyy

查看:168
本文介绍了如何将字符串转换为日期格式dd/MM/yyyy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

String date = '15/2/2014'
SimpleDateFormat simpleDate = new SimpleDateFormat("dd/MM/yyyy");
Date d = simpleDate.parse(date);

现在日期d返回: d = 2014年2月15日星期六00:00:00 MMT .

我想获得这种格式 d = '15/2/2014'

我该怎么办?

推荐答案

尝试一下:

String date="15/02/2014";
SimpleDateFormat dateFormat= new SimpleDateFormat("dd/MM/yyyy");

try {
  Date d=dateFormat.parse(date);
  System.out.println("DATE"+d);
  System.out.println("Formated"+dateFormat.format(d));
}
catch(Exception e) {
  //java.text.ParseException: Unparseable date: Geting error
  System.out.println("Excep"+e);
}

希望获得帮助.

这篇关于如何将字符串转换为日期格式dd/MM/yyyy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆