python中时间戳,字符串,时间元组之间的转换

港控/mmm° 2022-01-21 10:23 553阅读 0赞

把时间戳,去掉日时分秒,保留年月,方便判断是否是本月

  1. def get_month_timestamp(timestamp):
  2. #时间戳转为元组
  3. now = time.localtime(timestamp)
  4. #元组转为字符串
  5. monthStr = time.strftime("%Y-%m-00 00:00:00", now)
  6. #字符串转为元组
  7. monthTuple = time.strptime(monthStr, '%Y-%m-00 00:00:00')
  8. #元组转为时间戳
  9. return time.mktime(monthTuple)

发表评论

表情:
评论列表 (有 0 条评论,553人围观)

还没有评论,来说两句吧...

相关阅读