Python-6-1

Source: Internet
Author: User
1. Define a function that converts a timestamp into a formatted time

Import Time
def timestamp_to_fomat (timestamp= none,format = '%y-%m-%d%h:%m:%s '):
#1. Returns the current formatted time by default
#2. When the timestamp is passed, convert the timestamp to a formatted time and return
If timestamp:
Time_tuple = Time.localtime (timestamp)
res = Time.strftime (format,time_tuple)
Else
res = time.strftime (format) #默认取当前时间
return res
2.
define a well-formatted function to convert time stamps into timestamps:
def strtotimestamp (str=none,format= '%y%m%d%h%m%s '):
If str: #如果传了时间的话
TP = Time.strptime (str,format) #转成时间元祖
res = time.mktime (TP) #在转成时间戳
Else
res = Time.time () #默认取当前的时间戳
return int (res)

Python-6-1

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.