資源簡介
Python 3.7.3中文文檔 雙擊 文檔python-3.7.3-docs-html/index.html查看

代碼片段和文件信息
from?datetime?import?tzinfo?timedelta?datetime
ZERO?=?timedelta(0)
HOUR?=?timedelta(hours=1)
SECOND?=?timedelta(seconds=1)
#?A?class?capturing?the?platform‘s?idea?of?local?time.
#?(May?result?in?wrong?values?on?historical?times?in
#??timezones?where?UTC?offset?and/or?the?DST?rules?had
#??changed?in?the?past.)
import?time?as?_time
STDOFFSET?=?timedelta(seconds?=?-_time.timezone)
if?_time.daylight:
????DSTOFFSET?=?timedelta(seconds?=?-_time.altzone)
else:
????DSTOFFSET?=?STDOFFSET
DSTDIFF?=?DSTOFFSET?-?STDOFFSET
class?LocalTimezone(tzinfo):
????def?fromutc(self?dt):
????????assert?dt.tzinfo?is?self
????????stamp?=?(dt?-?datetime(1970?1?1?tzinfo=self))?//?SECOND
????????args?=?_time.localtime(stamp)[:6]
????????dst_diff?=?DSTDIFF?//?SECOND
????????#?Detect?fold
????????fold?=?(args?==?_time.localtime(stamp?-?dst_diff))
????????return?datetime(*args?microsecond=dt.microsecond
????????????????????????tzinfo=self?fold=fold)
????def?utcoffset(self?dt):
????????if?self._isdst(dt):
????????????return?DSTOFFSET
????????else:
????????????return?STDOFFSET
????def?dst(self?dt):
????????if?self._isdst(dt):
????????????return?DSTDIFF
????????else:
????????????return?ZERO
????def?tzname(self?dt):
????????return?_time.tzname[self._isdst(dt)]
????def?_isdst(self?dt):
????????tt?=?(dt.year?dt.month?dt.day
??????????????dt.hour?dt.minute?dt.second
??????????????dt.weekday()?0?0)
????????stamp?=?_time.mktime(tt)
????????tt?=?_time.localtime(stamp)
????????return?tt.tm_isdst?>?0
Local?=?LocalTimezone()
#?A?complete?implementation?of?current?DST?rules?for?major?US?time?zones.
def?first_sunday_on_or_after(dt):
????days_to_go?=?6?-?dt.weekday()
????if?days_to_go:
????????dt?+=?timedelta(days_to_go)
????return?dt
#?US?DST?Rules
#
#?This?is?a?simplified?(i.e.?wrong?for?a?few?cases)?set?of?rules?for?US
#?DST?start?and?end?times.?For?a?complete?and?up-to-date?set?of?DST?rules
#?and?timezone?definitions?visit?the?Olson?Database?(or?try?pytz):
#?http://www.twinsun.com/tz/tz-link.htm
#?http://sourceforge.net/projects/pytz/?(might?not?be?up-to-date)
#
#?In?the?US?since?2007?DST?starts?at?2am?(standard?time)?on?the?second
#?Sunday?in?March?which?is?the?first?Sunday?on?or?after?Mar?8.
DSTSTART_2007?=?datetime(1?3?8?2)
#?and?ends?at?2am?(DST?time)?on?the?first?Sunday?of?Nov.
DSTEND_2007?=?datetime(1?11?1?2)
#?From?1987?to?2006?DST?used?to?start?at?2am?(standard?time)?on?the?first
#?Sunday?in?April?and?to?end?at?2am?(DST?time)?on?the?last
#?Sunday?of?October?which?is?the?first?Sunday?on?or?after?Oct?25.
DSTSTART_1987_2006?=?datetime(1?4?1?2)
DSTEND_1987_2006?=?datetime(1?10?25?2)
#?From?1967?to?1986?DST?used?to?start?at?2am?(standard?time)?on?the?last
#?Sunday?in?April?(the?one?on?or?after?April?24)?and?to?end?at?2am?(DST?time)
#?on?the?last?Sunday?of?October?which?is?the?first?Sunday
#?on?or?after?Oct?25.
DSTSTART_1967_1986?=?datetime(1?4?24?2)
DSTEND_1967_1986?=?DSTEND_1987_2006
def?us_dst_range(year):
????#?Find?start?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2019-04-09?01:09??python-3.7.3-docs-html\
?????文件???????55478??2019-04-09?01:09??python-3.7.3-docs-html\genindex-T.html
?????目錄???????????0??2019-02-14?13:30??python-3.7.3-docs-html\_downloads\
?????目錄???????????0??2019-02-14?13:30??python-3.7.3-docs-html\_downloads\a01ac1c40eb86ec0f9e3c8e80f9eca65\
?????文件????????5860??2019-02-14?13:27??python-3.7.3-docs-html\_downloads\a01ac1c40eb86ec0f9e3c8e80f9eca65\tzinfo_examples.py
?????文件???????10648??2019-04-09?01:09??python-3.7.3-docs-html\genindex-Q.html
?????文件??????107837??2019-04-09?01:09??python-3.7.3-docs-html\ob
?????目錄???????????0??2019-02-14?13:29??python-3.7.3-docs-html\howto\
?????文件??????146103??2019-04-09?01:01??python-3.7.3-docs-html\howto\regex.html
?????文件??????300840??2019-04-09?01:01??python-3.7.3-docs-html\howto\logging-cookbook.html
?????文件??????108541??2019-04-09?01:01??python-3.7.3-docs-html\howto\logging.html
?????文件???????32483??2019-04-09?01:01??python-3.7.3-docs-html\howto\instrumentation.html
?????文件???????59324??2019-04-09?01:01??python-3.7.3-docs-html\howto\curses.html
?????文件???????76009??2019-04-09?01:01??python-3.7.3-docs-html\howto\unicode.html
?????文件???????81527??2019-04-09?01:01??python-3.7.3-docs-html\howto\argparse.html
?????文件????????9251??2019-04-09?01:01??python-3.7.3-docs-html\howto\index.html
?????文件???????47213??2019-04-09?01:01??python-3.7.3-docs-html\howto\pyporting.html
?????文件???????60129??2019-04-09?01:01??python-3.7.3-docs-html\howto\desc
?????文件???????37660??2019-04-09?01:01??python-3.7.3-docs-html\howto\ipaddress.html
?????文件??????154516??2019-04-09?01:01??python-3.7.3-docs-html\howto\functional.html
?????文件???????40176??2019-04-09?01:01??python-3.7.3-docs-html\howto\sockets.html
?????文件???????72427??2019-04-09?01:01??python-3.7.3-docs-html\howto\urllib2.html
?????文件???????42143??2019-04-09?01:01??python-3.7.3-docs-html\howto\cporting.html
?????文件???????47225??2019-04-09?01:01??python-3.7.3-docs-html\howto\sorting.html
?????文件??????131757??2019-04-09?01:01??python-3.7.3-docs-html\howto\clinic.html
?????文件??????577337??2019-04-09?01:00??python-3.7.3-docs-html\contents.html
?????目錄???????????0??2019-02-14?13:29??python-3.7.3-docs-html\faq\
?????文件???????59828??2019-04-09?01:01??python-3.7.3-docs-html\faq\extending.html
?????文件??????208717??2019-04-09?01:01??python-3.7.3-docs-html\faq\programming.html
?????文件???????29135??2019-04-09?01:01??python-3.7.3-docs-html\faq\windows.html
?????文件????????8242??2019-04-09?01:01??python-3.7.3-docs-html\faq\index.html
............此處省略1033個文件信息
評論
共有 條評論