将日期字符串转换为特定日期格式“dd-MM-yyyy”在Java中 [英] Convert date string to a particular date format "dd-MM-yyyy" in Java

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

问题描述

我有多个具有出生日期的联系人,并且都与移动设备同步。现在的问题是所有联系人都有不同的生日格式,我想以dd-MM-yyyy的格式显示所有生日日期。



所以对于例如,一个同步联系人的生日就像1990-02-07或1988-06-15T22:00:00.000Z或12-02-1990等...
然后所有这些日期应该以dd-MM-yyyy的格式显示。



那么如何解决这个问题?



任何建议将不胜感激。

解决方案

只需使用SimpleDateFormat类。如下所示:

 日期d = Calendar.getInstance()。getTime(); //当前时间
SimpleDateFormat sdf = new SimpleDateFormat(yyyy-MM-dd HH:mm); //设置日期格式
String currentData = sdf.format(d); //根据日期格式获取日期字符串

在此可以看到详细信息和所有支持的格式: p>

http://开发人员。 android.com/reference/java/text/SimpleDateFormat.html


I have multiple contacts with birth dates and all are synced with the mobile device. Now the problem is all contacts have different birthday formats and I want to display all of the birthday dates in a specific format like "dd-MM-yyyy".

So for example, one synchronized contact has birthday like "1990-02-07" or "1988-06-15T22:00:00.000Z" or "12-02-1990" etc... Then all of these dates should be displayed in a specific format "dd-MM-yyyy".

So how can I resolve this issue?

Any suggestion will be appreciated.

解决方案

Simply using SimpleDateFormat class. Something like:

Date d = Calendar.getInstance().getTime(); // Current time
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); // Set your date format
String currentData = sdf.format(d); // Get Date String according to date format

Here you can see details and all supported format:

http://developer.android.com/reference/java/text/SimpleDateFormat.html

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

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