>>>time.time () # Returns the current timestamp1514623449.8858318>>>type (Time.time ())<class 'float'>>>>>>> Time.sleep (2# thread postpones the specified time to run. Unit is seconds. >>> Type (Time.sleep (2))<class 'Nonetype'>>>>>>>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. (actually based on QueryPerformanceCounter () on WIN32, which is more accurate than milliseconds)0.044762>>>type (Time.clock ())<class 'float'>>>>>>>time.localtime () #将一个时间戳转换为当前时区的struct_time. The secs parameter is not provided, whichever is the current time. Time.struct_time (Tm_year= ., tm_mon= A, tm_mday= -, tm_hour= -, tm_min= the, tm_sec=9, tm_wday=5, tm_yday=364, tm_isdst=0>>>type (Time.localtime ())<class 'Time.struct_time'>>>>Time.gmtime () is similar to the #和localtime () method, the Gmtime () method is a struct_time that converts a timestamp to the UTC time zone (0 o'clock Zone). Time.struct_time (Tm_year= ., tm_mon= A, tm_mday= -, tm_hour=8, tm_min= About, tm_sec=2, tm_wday=5, tm_yday=364, tm_isdst=0)>>>type (Time.gmtime ())<class 'Time.struct_time'># # #注意: tm_wday, calculated is 0-6, so the day of the week will be pushed backwards. Above tm_wday=3, expressed in Thursday. >>>Time.mktime (Time.localtime ()) #将一个struct_time转化为时间戳. 1514624361.0>>>type (Time.mktime (Time.localtime ()))<class 'float'>>>> Time.asctime () # represents a tuple or struct_time representing time as this form:'Sun June 23:21:05 1993'. If there are no parameters, Time.localtime () will be passed in as a parameter. 'Sat Dec 17:00:42'>>>type (Time.asctime ())<class 'Str'>>>>>>>The time.ctime () #把一个时间戳 (floating-point number in seconds) is converted to Time.asctime () Form. If the parameter is not given or is none, the default Time.time () is the parameter. Its function is equivalent to Time.asctime (time.localtime (secs)). 'Sat Dec 17:02:37'>>>Time.ctime (Time.time ())'Sat Dec 17:03:43'>>> Time.ctime (1304579615)'Thu May 5 15:13:35'>>>>>>type (Time.ctime ())<class 'Str'>>>>time.strftime (format[, T]): #把一个代表时间的元组或者struct_time, such as returned by Time.localtime () and Time.gmtime (), into a formatted time string. If T is not specified, the Time.localtime () is passed in. If any of the elements in the tuple are out of bounds, the ValueError error will be thrown. Format meaning remarks%a local (locale) simplifies week name%A Local Full week name%b Local simplified month name%B Local Full month name%c Local corresponding date and time representation%d the first day of the one months ( on- to)%H the first hours of the day (24-hour system,xx- at)%I Hours (12-hour system, on- A)%j the first day of the year (001-366)%m Month ( on- A)%M minutes (xx- -)%p The corresponding selector of the local AM or PM%s seconds ( on- A) Two%u the number of weeks in a year. (xx-53 Weeks is the beginning of one weeks. All days before the first Sunday are placed in the No. 0 week. Three%w the day of the one week (0-6, 0 is Sunday) three%W and%u are basically the same, the difference is%W takes Monday as the beginning of one weeks. %x Local corresponding date%X Local corresponding time%y to remove the years of the Century (xx- About)%Y Full Year%the name of the Z time zone (if it does not exist as a null character)%% ‘%' word Fu Bei Note:1.“ %p "only with"%I "works with the effect. 2The document highlights the fact that it is 0- A, not 59, leap year seconds to two seconds (sweat one). 3When using the Strptime () function,%u and% only when the number of weeks and days in the year is determinedW will not be counted. >>> Time.strftime ('%y-%d-%m%x', Time.localtime ())'2017-30-12 17:09:23'>>>Time.strptime (string[, format]): #把一个格式化时间字符串转化为struct_time. In fact it is inverse operation with strftime (). >>> Time.strptime ('2017-12-30 15:14:34','%y-%m-%d%x') time.struct_time (tm_year= ., tm_mon= A, tm_mday= -, tm_hour= the, tm_min= -, tm_sec= the, tm_wday=5, tm_yday=364, tm_isdst=-1)>>>
Time Module Summary:
First, there are three forms of expression: timestamp, tuple, formatted string
Their transformation relationship:
0. Get the number of connections for TCP in various states:
netstat -n | awk ‘/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}‘
Python Date-time usage