Android的:获取当前日期和时间 [英] Android: Getting the current date and time
本文介绍了Android的:获取当前日期和时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图让今天的日期,并使用以下code时,
I am trying to get the today's date and time using the following code,
SimpleDateFormat sdf = new SimpleDateFormat("dd/mm/yyyy HH:mm");
String currentDateandTime = sdf.format(new Date());
但结果是
26/15/2014 13:15 26/1/2014 13:15
26/15/2014 13:15 instead of 26/1/2014 13:15
什么是错的?
谢谢!
推荐答案
替换MM第一毫米。在 http://developer.android.com/reference/java/text/检查文档SimpleDateFormat.html
Replace first mm with MM. Check documentation at http://developer.android.com/reference/java/text/SimpleDateFormat.html
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm");
String currentDateandTime = sdf.format(new Date());
这篇关于Android的:获取当前日期和时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文