您的位置:首页 > 编程语言 > Java开发

《Java编程技巧1001条》第373条: 了解不同的日期标准,

2017-12-20 15:08 537 查看



《Java编程技巧1001条》第9章 Java日期函数第373条 了解不同的日期标准
 

373 Understanding Different Date Standards
373 弄清不同的日期标准

The basis for standard time throughout the world is the meridian at Greenwich, England. You can specify the time for any location in the world in terms of the number of hours from Greenwich Mean Time, or simply GMT. Java uses midnight GMT, January 1st, 1970 for its epoch date. Java provides methods you can use to express the time based on two time locations: the time at Greenwich and your local time. Of course, the classes determine the time based on your computers clock and time-zone settings. Thus, you must make sure that both your systems time and time-zone settings are correct. When you need to express the time and date in terms of GMT, you can use the Date class toGMTString method. If you need the time expressed in the local time, use Date class toLocaleString method. The Date class getTimezoneOffset method determines the local time-zone offset, which is the number of minutes your program must add to Greenwich Mean Time to give the local time zone. This value includes the correction,if necessary, for daylight savings time.
全世界的基本标准时间是英国格林威治子午线时间. 你可以用从格林威治平均时间(简记为GMT)开始算起的时数来表示世界上任何一个地区的时间. Java用1970年1月1号,12点(GMT)作为时代时间. Java为你提供了用两个时间位置来表示时间的方法,即格林威治时间和你的局部地区时间. 当然,实际的计算还决定于你的计算机的时钟和时间地区(time-zone)的设置. 因此,你必须保证你的系统时间和时间地区的设置都正确无误. 当你需要用GMT标准表示时间和日期时,你可使用Date类的toGMTString方法, 如果你想得到局部地区时间时,则你可使用Date类中的toLocaleString方法. Date类中的getTimezoneOffset方法则用来设置时间地区,它代表你所在的局部地区时间与GMT时间之间相差的分数,在你的程序中只要把这一分数加到GMT时间上,就可得到你所在的局部地区时间.

TIME \@ "MMMM d, yyyy"
November 24, 1996
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: