Tutorial on using the Tzset () method of operation time in Python

Source: Internet
Author: User
The Tzset () method resets the time conversion rules for the library routines that are used. Environment variable TZ Specifies how to complete this operation.

The standard format of the TZ environment variable (spaces are added for clarity):

The code is as follows:

STD offset [DST [offset [, Start[/time], End[/time]]

    • STD and DST: three or more alphanumeric give people the time zone abbreviation. These will be spread to time.tzname.
    • Offset: Offsets are in the form:. Hh[:mm[:ss]]. This indicates that the value added local time arrives in UTC. If preceded by a "-", the time zone is east of the Prime meridian, otherwise it is the west. If there is no offset following DST, the summer time is assumed to be one hour ahead of the standard time.
    • Start[/time], End[/time]: Indicates when changed to and returned from daylight. The start and end date formats are performed in one of the following actions:
    • Jn: In Julian date n (1 <= n <= 365). Leap Day is not counted, so the February 28 of each year is the 59th and March 1 is 60 days.
    • N: The zero-based Julian date (0<= n<=365). Leap year days are counted, and can refer to February 29.
    • MM.N.D: X Days (0<= d<= 6) or week N of the year of the Month m (1 <= n <=5,1<= m <=12, of which 5 per week represents "at the end D-Sun M", which may occur in either of the four or fifth weeks). Week 1 is where D day occurs in the first week. 0 is Sunday.
    • Time: This is different from the same format offset, and no leading symbol ("-" or "+") is allowed. By default, if time is not given, it is 02:00:00.

Grammar

The following is the syntax for the Tzset () method:

Time.tzset ()

Parameters

    • NA

return value

This method does not return any values.
Example

The following example shows the use of the Tzset () method.

#!/usr/bin/pythonimport timeimport osos.environ[' TZ '] = ' est+05edt,m4.1.0,m10.5.0 ' Time.tzset () print time.strftime (' %x%x%Z ') os.environ[' TZ '] = ' aest-10aedt-11,m10.5.0,m3.5.0 ' Time.tzset () print time.strftime ('%x%x%Z ')

When we run the above program, it produces the following results:

13:00:40 02/17/09 est05:00:40 02/18/09 AEDT
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.