获得天,月,年分别使用的SimpleDateFormat [英] Get day, month and year separately using SimpleDateFormat

查看:433
本文介绍了获得天,月,年分别使用的SimpleDateFormat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 SimleDateFormat 像这样

SimpleDateFormat format = new SimpleDateFormat("MMM dd,yyyy  hh:mm");
String date = format.format(Date.parse(payback.creationDate.date));

我给日期的格式如简,23,2014

现在,我想单独获得天,月,年。我怎样才能实现呢?

Now, I want to get day, month and year separately. How can I implement this?

推荐答案

如果您需要分别得到的值,然后使用一个以上的的SimpleDateFormat

If you need to get the values separately, then use more than one SimpleDateFormat.

SimpleDateFormat dayFormat = new SimpleDateFormat("dd");
String day = dayFormat.format(Date.parse(payback.creationDate.date));

SimpleDateFormat monthFormat = new SimpleDateFormat("MM");
String month = monthFormat .format(Date.parse(payback.creationDate.date));

等。

这篇关于获得天,月,年分别使用的SimpleDateFormat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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