java 如何在java中获取默认日期模式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27833515/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get default date pattern in java?
提问by Alin
public class DefaultDateFormatPattern {
public static void main(String[] args) {
System.out.println(new Date());
}
}
The output is: Thu Jan 08 10:52:56 IST 2015
输出是: Thu Jan 08 10:52:56 IST 2015
Is there any method in Java to get the pattern of the date it is showing ?
Java中是否有任何方法可以获取它显示的日期模式?
回答by Braj
You can try SimpleDateFormat.toLocalizedPattern()or SimpleDateFormat.toPattern()to get the pattern.
您可以尝试SimpleDateFormat.toLocalizedPattern()或SimpleDateFormat.toPattern()来获取模式。
SimpleDateFormat format=new SimpleDateFormat();
System.out.println(format.toLocalizedPattern());
System.out.println(format.toPattern());
Pass locale to get the locale specific pattern.
传递语言环境以获取特定于语言环境的模式。
回答by muaz
According to Java 8 toString()
method of Date
class the format is: EEE MMM dd HH:mm:ss zzz yyyy
.
根据类的Java 8toString()
方法,Date
格式为:EEE MMM dd HH:mm:ss zzz yyyy
.
回答by Pavan
You can use SimpleDateFormat to get whatever the date format you want. The default format of SimpleDateFormat is
您可以使用 SimpleDateFormat 来获取您想要的任何日期格式。SimpleDateFormat 的默认格式是
d/M/yy h:mm a
d/M/yy h:mm a
you can set the way you want.
你可以设置你想要的方式。
Eg.
例如。
SimpleDateFormat format=new SimpleDateFormat("dd/MM/yyyy");
System.out.println(format.format(new Date()));
回答by Sharp Edge
Calendar rightNow = Calendar.getInstance();
DateFormat d = new SimpleDateFormat("DDD", Locale.getDefault());
String day = d.format(rightNow.getTime());
You can use the overloaded constructor of SimpleDateFormat
to get the current default use Locale.getDefault()
in the 2nd argument..
Check the SimpleDateFormat Api Docs
您可以使用重载的构造函数SimpleDateFormat
来获取Locale.getDefault()
第二个参数中的当前默认使用。检查SimpleDateFormat Api Docs