在Java中以HTTP格式获取日期 [英] Getting Date in HTTP format in Java
本文介绍了在Java中以HTTP格式获取日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图以Java 1.1中指定的格式获取Java中的日期字符串。据我所知,这是:
I'm trying to get a String of a date in Java in the format specified in HTTP 1.1. Which, as far as I can tell, is:
星期五,1999年12月31日23:59:59 GMT
Fri, 31 Dec 1999 23:59:59 GMT
随着时间总是GMT。
从日期开始,最简单的方法是什么/日历/?
What would be the easiest way to get this from Date/Calendar/?
推荐答案
如果有人会尝试在这里找到答案(像我这样做),这将是什么技巧:
In case someone else will try to find the answer here (like I did) here's what will do the trick:
String getServerTime() {
Calendar calendar = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat(
"EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
return dateFormat.format(calendar.getTime());
}
为了设置服务器说英语并给予GMT时区的时间。
in order to set the server to speak English and give time in GMT timezone.
这篇关于在Java中以HTTP格式获取日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文