Python-time-datetime

Source: Internet
Author: User
Tags add time

Import time

Time.time () #为当前日期与UNIX纪元时间戳相差多少秒

Import datetime

Datetime.datetime.now () returns the DateTime object for the current time

Dt=datetime.datetime (2015,2,27,16,29,0) can pass in years, months, days, hours, minutes, seconds

Datetime.datetime.fromtimestamp (100000) incoming timestamp can be converted to datetime.datetime format

Datetime.datetime.fromtimestamp (Time.time ())

Delta=datetime.timedelta (days=11,hours=10,minutes=9,seconds=8) it represents a period of time

Delta.total_seconds () It is the number of seconds that this period represents

Print (S+DT) to add time and datetime.datetime format

Dateasstring=dt.striftime ('%y-%m-%d%h:%m:%s ') converts the Datetime.datetime format to a string

Stringasdate=dateasstring (dateasstring, '%y-%m-%d%h:%m:%s ') converts a string to datetime.datetime format, followed by a formatted string that needs to be consistent with the DateTime format

Python-time-datetime

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.