如何为 Android 平台正确设置日期和时间字符串的格式?
这是一些代码:
字符串路径 = getFilesDir().getPath();
String filePath = 路径 + "/somefile.xml";
文件 file = new File(filePath);
日期lastModDate = new Date(file.lastModified());
String filelastModDate = "更新:"+ lastModDate.toString();
最佳答案
您可以通过多种方式对其进行格式化...
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("h:mm a");
String currentTime = sdf.format(date);
这里你可以输入其他格式,例如
k:毫米
高:毫米
时:月/日/月/年
等等......
检查这个.... http://developer.android.com/reference/java/text/SimpleDateFormat.html
关于java - Android:如何正确格式化日期和时间字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20311306/