Week number of year in python

| No Comments | No TrackBacks

早晨有同事问为什么Python里的datetime模块使用strftime("%W")取出来的Week number不对呢,好象差一周。使用date "+%W"得出的结果与Python的结果是一致的。

造成这种差异的原因是对于周数的定义不太一致,通常使用的周数指的是ISO 8601中定义的。要输出这个ISO格式的周数应当使用strftime("%V")%U%W%V的区别在strftime(3)说的明白。虽然Python在strftime文档里没有说明可以使用%V格式化,但是在2.3、2.4、2.5和2.6里测试都可以正常的输出ISO的周数。Python提供的另外一种方法是isocalendar(),这个方法返回一个tuple(Year, WeekOfYear, DayOfWeek)

No TrackBacks

TrackBack URL: http://mt.khsing.net/cgi-bin/mt-tb.cgi/80

Leave a comment

About this Entry

This page contains a single entry by Guixing published on August 5, 2009 7:07 AM.

MB990的CPU型号 was the previous entry in this blog.

Mac的一般用户怎么改Hosts文件 is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.