我怎样才能得到当前日期的Andr​​oid? [英] How can I get current date in Android?

查看:105
本文介绍了我怎样才能得到当前日期的Andr​​oid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了下面code

Date d = new Date();
CharSequence s  = DateFormat.format("MMMM d, yyyy ", d.getTime());

但问我的参数,我想当前日期字符串格式,

But is asking me parameter, I want current date in string format,

喜欢

28-Dec-2011

这样我就可以设置了的TextView

解释一下,如果你认为有些东西是必须的,我是新来的Andr​​oid开发。

explain a bit, if you think something is necessary, I am new to Android Development.

推荐答案

您可以使用<一个href="http://developer.android.com/reference/java/text/SimpleDateFormat.html"><$c$c>SimpleDateFormat类在你想要的格式格式化日期。

You can use the SimpleDateFormat class for formatting date in your desired format.

只要检查该链接,你的想法你的例子。

Just check this link where you get idea for your example.

例如:

String dateStr = "04/05/2010"; 

SimpleDateFormat curFormater = new SimpleDateFormat("dd/MM/yyyy"); 
Date dateObj = curFormater.parse(dateStr); 
SimpleDateFormat postFormater = new SimpleDateFormat("MMMM dd, yyyy"); 

String newDateStr = postFormater.format(dateObj); 

更新:

详细的例子是<一个href="https://web.archive.org/web/20080614071809/http://www.itgalary.com/forum_posts.asp?TID=885">here和这里,我建议你去通过这个例子,理解的SimpleDateFormat类的概念。

Update:

Detailed example is here and here, I would suggest you to go through this example and understand the concept of SimpleDateFormat class.

Calendar c = Calendar.getInstance();
System.out.println("Current time => " + c.getTime());

SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
String formattedDate = df.format(c.getTime());

这篇关于我怎样才能得到当前日期的Andr​​oid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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