Python Time processing Time,datetime,arrow

Source: Internet
Author: User
Tags timedelta

Built-in time

# Timestamp Conversion system time 2018-04-04 11:00:55# CTime = Time.localtime (Time.time ()) # Print (Time.strftime ('%y-%m-%d%h:%m:%s ', CTime)) # Sleep 1 seconds (seconds) # print (Time.sleep (1)) # Output current system time # x = Time.localtime () # t = time.strftime ('%y-%m-%d%h:%m:%s ', x) # Enter the current time by format , x = tuple # print (t) # 2018-02-06 16:37:30
# convert time array # dt = "2016-05-05 20:28:54" # DT2 = time.strptime (dt, "%y-%m-%d%h:%m:%s") # Time.struct_time (tm_year=2016, tm_mon= 5, Tm_mday=5, tm_hour=20, tm_min=28, tm_sec=54, tm_wday=3, tm_yday=126, Tm_isdst=-1) # in Conversion date Time # DT3 = Time.strftime ("%Y-%m -%d%h:%m:%s ", DT2) # print (DT3)

  

Built-in datetime can be date plus minus
# Encapsulation of the time module import datetime#%y-%m-%d%h:%m:%s# month Day minute # current date # print (' Current date: ', Datetime.datetime.now ()) # Current Date: 2018- 04-04 11:04:46.090568# Date Added (3 days after date) # print (Datetime.datetime.now () + Datetime.timedelta (3)) # 2018-04-07 11:04:46.090568# date subtraction 3 days ago # print (Datetime.datetime.now () + Datetime.timedelta (-3)) # hours added, 3 minus # print ( Datetime.datetime.now () + Datetime.timedelta (hours=3)) # time Replacement # c_time = Datetime.datetime.now () # Print (C_time.replace ( year=2019) # 2019-04-04 11:29:47.653526# The time type returned by the database query, conversion bit # t = datetime.datetime (2018, 4, 4, ten,, and 793000). strf Time ('%h:%m ') # 10:48# print (t) # t_str = ' 2012-03-05 16:26:23 ' # Converts a string to a datetime date string = = datetime# D = Datetime.da Tetime.strptime (T_str, '%y-%m-%d%h:%m:%s ') # so you can add and subtract # print (D + datetime.timedelta (-3)) # 2 Date comparison # D1 = Datetime.datetime.strptime (' 2012-03-05 17:41:20 ', '%y-%m-%d%h:%m:%s ') # D2 = Datetime.datetime.strptime (' 2012-03-02 17:41:20 ', '%y-%m-%d%h:%m:%s ') # delta = d1-d2# print (delta.days)
Arrow Gallery

Installing PIP Install arrow

Import arrow# Get current time Now2 = Arrow.utcnow () # timestamp timestamp# print (now2.timestamp) #now = Arrow.now () print (Now.timestamp) # Timestamp # t = Now.format (' Yyyy-mm-dd hh:mm ') # 2018-04-04 09:39# print (' Current time ', t) # MM = Start.format (' hh:mm ') # 09:48# current time plus 1 Minutes # n = now.shift (Minutes=1) # print (' Current time plus 1 minutes ', N.format (' Yyyy-mm-dd hh:mm ')) # current time plus 1 hours # n = now.shift (Hours=1) # print (' Current time plus 1 hours ', N.format (' Yyyy-mm-dd hh:mm ')) # n = now.shift (Months=1) # print (' Current time plus January ', N.format (' Yyyy-mm-dd hh:mm ')) # n = Now.shift (Years=1) # print (' Current time plus 1 years ', N.format (' Yyyy-mm-dd hh:mm ')) # n = now.shift (Days=1) # print (' Current time plus 1 days ', N.format (' Yyyy-mm-dd hh:mm ') # n = now.shift (days=-1) # print (' Current time plus-1 days ', N.format (' Yyyy-mm-dd hh:mm ')) # n = now.shift (Weeks=1) # Print (' Current time plus 1 weeks ', N.format (' Yyyy-mm-dd hh:mm ')) #----------------Convert Arrow Object # String to convert arrow Object # Strarr = Arrow.get (" 2017-01-20 "," Yyyy-mm-dd hh:mm ") # year = Strarr.format (' YYYY ') # Print (years) # timestamp conversion Arrow Object # SJC = Arrow.get (" 1485937 858.659424 "). Format (" Yyyy-mm-dd ") # print (SJC) # Direct production of a ArroW Object # aw = arrow. Arrow (2, 1) # Print (Aw.format (' Yyyy:mm-dd hh:mm '))

Python Time processing Time,datetime,arrow

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.