Python UNIX_TIMESTAMP time processing method analysis, unixtimestamp

Source: Internet
Author: User

Python UNIX_TIMESTAMP time processing method analysis, unixtimestamp

This article describes how to process the time of python UNIX_TIMESTAMP. We will share this with you for your reference. The details are as follows:

from datetime import datetimeimport timeint(time.mktime(rm.start_time.timetuple())) datetime.fromtimestamp(time.time())rf.start_time + timedelta(0, math.ceil(diff.total_seconds()/(3600*rf.period))*3600*rf.period)

Obtains the offset time of a month or hour.

def getlastday(datetimeobj): year= datetimeobj.year month = datetimeobj.month + 1 if month>12:  year = year + 1  month=1 return datetime(year, month, 1) - timedelta(1)def getSendTime(period, start_time): datenow = datetime.now() nextTime = preTime = start_time if period > 0 and period < 1000:  diff = datetime.now() - start_time  nextTime = start_time + timedelta(0, math.ceil(diff.total_seconds()/(3600*period))*3600*period)  preTime = start_time + timedelta(0, math.floor(diff.total_seconds()/(3600*period))*3600*period) if period == 1001:  if datenow.day>start_time.day:   preTime = datetime(datenow.year, datenow.month, start_time.day)   nextTime = getlastday(getlastday(datenow)+timedelta(1))   if nextTime.day > start_time.day:    nextTime = datetime(nextTime.year, nextTime.month, start_time.day)  else:   preTime = getlastday(datetime(datenow.year, datenow.month, 1) - timedelta(1))   if preTime.day > start_time.day:    preTime = datetime(preTime.year, preTime.month, start_time.day)   nextTime = getlastday(datenow)   if nextTime.day > start_time.day:    nextTime = datetime(nextTime.year, nextTime.month, start_time.day) return preTime, nextTime

Sort

reportMetaPeriodInfo.sort(lambda p1, p2:cmp(p1['k'], p2['k']))

Get ip

import sockets = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)  s.connect(('8.8.8.8', 0))  localIP=s.getsockname()[0]

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.