public class DefaultDateFormatPattern {
public static void main(String[] args) {
System.out.println(new Date());
}
}
输出结果为:
Thu Jan 08 10:52:56 IST 2015
在Java中有没有获取所显示日期格式的方法?public class DefaultDateFormatPattern {
public static void main(String[] args) {
System.out.println(new Date());
}
}
Thu Jan 08 10:52:56 IST 2015
在Java中有没有获取所显示日期格式的方法?Date
类的toString()
方法,格式如下:EEE MMM dd HH:mm:ss zzz yyyy
。Date
类)。 - Ole V.V.SimpleDateFormat format=new SimpleDateFormat();
System.out.println(format.toLocalizedPattern());
System.out.println(format.toPattern());
Date.toString()
方法,看看它做了什么。 - Braj Calendar rightNow = Calendar.getInstance();
DateFormat d = new SimpleDateFormat("DDD", Locale.getDefault());
String day = d.format(rightNow.getTime());
您可以使用 SimpleDateFormat
的重载构造函数来获取当前默认的语言环境,请在第二个参数中使用 Locale.getDefault()
。
请查看 SimpleDateFormat Api文档。
SimpleDateFormat format=new SimpleDateFormat("dd/MM/yyyy");
System.out.println(format.format(new Date()));
java.text.SimpleDateFormat
一起使用的模式字符串吗? - ez121slLocales
和getDefault()
。 - Sharp EdgeDate
和SimpleDateFormat
。这些类设计得很差,而且已经过时了。相反,使用来自java.time,现代Java日期和时间API的Instant
表示时间点。其toString
方法生成的格式为DateTimeFormatter.ISO_INSTANT
。 - Ole V.V.