Android:如何正确格式化日期和时间字符串? [英] Android: How to Format Date and Time Strings correctly?

查看:705
本文介绍了Android:如何正确格式化日期和时间字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该如何正确格式化Android平台的日期时间字符串?

这是一些代码:

解决方案

您可以采用多种方式设置其格式...

Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("h:mm a");
String currentTime = sdf.format(date);

在这里您可以输入其他格式,例如

k:mm

h:mm

h:mm dd/MM/yyyy
等等.....

检查此内容.... http://developer.android.com/reference/java/text/SimpleDateFormat.html

How should I correctly format Date and Time Strings for the Android platform?

Here is some code:

String path = getFilesDir().getPath();
String filePath = path + "/somefile.xml";
File file = new File(filePath);
Date lastModDate = new Date(file.lastModified());
String filelastModDate = "Updated: " + lastModDate.toString();

解决方案

You can format it various way...

Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("h:mm a");
String currentTime = sdf.format(date);

Here you can put other format like

k:mm

h:mm

h:mm dd/MM/yyyy
etc.....

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

这篇关于Android:如何正确格式化日期和时间字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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