在使用SimpleDateFormat时格式化时间的 yyyy.MM.dd 为年月日而如果希望格式化时间为12小时制的,则使用hh:mm:ss 如果希望格式化时间为24小时制的,则使用HH:mm:ss
代码如下:
- Date d = new Date();
- SimpleDateFormat ss = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//12小时制
- System.out.println(ss.format(d));
- Date date = new Date();
- SimpleDateFormat sdformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//24小时制
- String LgTime = sdformat.format(date);
- System.out.println(LgTime);
public static Date getDate(String dateStr, String format)
{
SimpleDateFormat sdf;
try
{
sdf = new SimpleDateFormat(format);
}
catch (Exception e1)
{
return null;
}
Date d;
try
{
d = sdf.parse(dateStr);
return d;
}
catch (ParseException e)
{
}
return null;
}
android 获取系统时间
new Date(System.currentTimeMillis())