挑日,月,年出file.lastModified(); [英] Pick day, month and year out file.lastModified();
本文介绍了挑日,月,年出file.lastModified();的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如何使用 file.lastModified();
。
当我的println
,我得到(例如):周六3月17日9时24分33秒GMT + 01:00 2012
但是,它可能是我只得到日,月,年为数字,例如:17 03房价
I know how to use file.lastModified();
.
When I println
that I get (for example): Sat Mar 17 09:24:33 GMT+01:00 2012.
But is it possible that I only get the day, month and year as numbers, for example: 17 03 2012
他们是一个办法做到这一点,也许一个过滤器或其他功能来获得数字最后修改日期?
Is their a way to do this, maybe a filter, or an other function to get last modified date in numbers?
推荐答案
您可以使用的SimpleDateFormat 类,即
package com.example.file;
import java.io.File;
import java.text.SimpleDateFormat;
public class GetFileLastModifiedExample
{
public static void main(String[] args)
{
File file = new File("\\somefile.txt");
System.out.println("Before Format : " + file.lastModified());
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
System.out.println("After Format : " + sdf.format(file.lastModified()));
}
}
这篇关于挑日,月,年出file.lastModified();的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文