Python Learning note 9: Time of the logo library

Source: Internet
Author: User
Tags date1 local time timedelta

One time Package
Sleep ([float time]) delays a number of seconds in floating-point numbers


The time package is based on the C language library function (functions).
Python's interpreter is usually written in C, and some Python functions directly invoke the C-language library function.


Time.time () Get current time, return float type, Unit: sec
Time.clock () on UNIX systems, it returns "process time", which is a floating-point number (timestamp) in seconds.
In Windows, the first call returns the actual time that the process is running. The second subsequent call is the elapsed time since the first call to the present.


Time.gmtime () returns UTC time in Struct_time format
The Time.localtime ([float time]) parameter is a UTC and returns the Time.struct_time type
Returns the local time in the Struct_time format, depending on the system environment, when there is no parameter
Time.mktime ([float time]) converts a timestamp into the struct_time of a UTC time zone (0 o'clock Zone),
If the seconds parameter is not entered, the current time is the conversion standard


Two datetime packages
DateTime can be understood as both a date and a time component.
Date is the day (equivalent to the calendar) of the month and date, which is the exact time (equivalent to a watch) in 24 hours of the day, minutes and seconds.
You can manage the two separately (the Datetime.date class, the Datetime.time Class), or you can combine them (the Datetime.datetime class).


1 Date Class
Class Properties:
A datetime module defines two constants: DateTime. Minyear and Datetime.maxyear, respectively, representing the minimum and maximum year that datetime can represent.
wherein, Minyear = 1,maxyear = 9999.


Datetime.date: A class that represents a date. Commonly used properties are year[minyear, Maxyear], month[1,12], day[1,31];
Datetime.time: A class that represents time. The commonly used properties are hour, minute, second, microsecond;
Datetime.datetime: Represents the date and time.
Datetime.timedelta: Represents the time interval, which is the length between two points in time.




Instance properties:
Date.year, Date.month, Date.day: Year, month, day;
Date.replace (year, Month, day): Generates a new Date object, substituting the attributes in the original object with the years, months, and days specified by the parameter.
Date.timetuple (): Returns the Time.struct_time object corresponding to the date;
Date.toordinal (): Returns the date corresponding to the Gregorian calendar date;
Date.weekday (): Returns weekday, if it is Monday, returns 0 if it is Week 2, returns 1, and so on;
Data.isoweekday (): Returns weekday, if it is Monday, returns 1 if it is Week 2, returns 2, and so on;
Date.isocalendar (): Returns a tuple with a format such as (Year,month,day);
Date.isoformat (): Returns a string formatted as ' YYYY-MM-DD ';
Date.strftime (FMT): Custom formatted string.


Overloaded operations:
Date2 = date1 + Timedelta # date plus an interval, returns a new Date object (Timedelta will be described below, representing the time interval)
Date2 = date1-timedelta # date interval, returns a new Date object
Timedelta = date1-date2 # Two date subtraction, returns a time interval object
Date1 < Date2 # Two dates to compare


2 Time Class
Class Properties:
The minimum and maximum time that the Time.min, Time.max:time class can represent. wherein, Time.min = time (0, 0, 0, 0), Time.max = time (23, 59, 59, 999999);
Time.resolution: The smallest unit of time, typically 1 microseconds;
Instance properties:
Time.hour, Time.minute, Time.second, Time.microsecond: Hours, minutes, seconds, microseconds;
Time.tzinfo: time zone information;
Time.replace ([hour[, minute[, second[, microsecond[, Tzinfo]]]]): Creates a new Time object, replaces the attributes in the original object with the time, minute, second, and microsecond specified by the parameter (the original object remains unchanged) ;
Time.isoformat (): A string representation of the return type, such as "HH:MM:SS" format;
Time.strftime (FMT): Returns a custom formatted string.


3 datetime class
DateTime is a combination of date and time, including all information about date and time. Its constructor is as follows:
Datetime.datetime (year, month, day, hour, minute, second, microsecond, tzinfo), each parameter has the same meaning as in the date, time constructor.


Class Properties:
The minimum and maximum values that can be expressed by datetime.min and Datetime.max:datetime;
Datetime.resolution:datetime minimum Unit;
Datetime.today (): Returns a DateTime object representing the current local time;
DateTime.Now ([TZ]): Returns a DateTime object that represents the current local time, and if the parameter tz is provided, gets the local time of the time zone referred to by the TZ parameter;
Datetime.utcnow (): Returns a DateTime object for the current UTC time;
Datetime.fromtimestamp (timestamp[, TZ]): Creates a DateTime object according to the time timestamp, and the parameter TZ specifies the time zone information;
Datetime.utcfromtimestamp (timestamp): Creates a DateTime object based on the time timestamp;
Datetime.combine (date, time): Creates a DateTime object based on date and time;
Datetime.strptime (date_string, format): Converts a format string to a DateTime object;
Instance properties:
Datetime.year, month, day, hour, minute, second, microsecond, Tzinfo:
Datetime.date (): Gets the Date object;
Datetime.time (): Gets the time object;
Datetime.replace ([year[, month[, day[, hour[, minute[, second[, microsecond[, Tzinfo] []]] []]):
Datetime.timetuple ()
Datetime.utctimetuple ()
Datetime.toordinal ()
Datetime.weekday ()
Datetime.isocalendar ()
Datetime.isoformat ([Sep])
Datetime.ctime (): Returns a C-format string of datetime equivalent to Time.ctime (Time.mktime (Dt.timetuple ()));
Datetime. Strftime (format)
Like date, you can compare two DateTime objects, or subtract a time interval object, or return a new DateTime object with a DateTime plus an interval.




Three-format string
datetime, date, and time all provide the strftime () method, which receives a format string that outputs a string representation of the DateTime.


The following are the meanings of the format characters:


%a: Shorthand for the week. As Wednesday for web
%A: Full write of the week. As in Wednesday for Wednesday
%b: Shorthand for the month. If April is Apr
%B: Full write of the month. As in April for April
%c: string representation of DateTime. (Example: 04/07/10 10:43:39)
%d: The number of days in the month (the day of the week)
%f: microseconds (range [0,999999])
%H: Hours (24-hour, [0, 23])
%I: Hours (12-hour, [0, 11])
%j: Number of days in the year [001,366] (the day of the current year)
%m: Month ([01,12])
%M: Minutes ([00,59])
%p:am or PM
%s: seconds (range = [00,61], why not [00, 59], refer to Python manual ~_~)
%u: Week in the Year of the Week of the year), Sunday as the first day of the week
%w: Today in this week's days, the range is [0, 6],6 represents Sunday
%W: Week of the Year (the Week of the year), Monday as the first day of the week
%x: Date string (for example: 04/07/10)
%x: Time string (for example: 10:43:39)
%y:2 the year represented by a number
%y:4 the year represented by a number
%z: Interval with UTC time (if local time, returns an empty string)
%Z: Time zone name (if local time, returns an empty string)
Percent:%


There is a lot of content and no code available.

Python Learning note 9: Time of the logo library

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.