简体   繁体   English

python datetime到excel序列号

[英]python datetime to excel serial number

How to convert (YY,MM,DD,HH,MM,SS) to the Excel "serial" datetime number. 如何将(YY,MM,DD,HH,MM,SS)转换为Excel“序列”日期时间数字。

Example: 12/23/2017 10:00:00 PM to 43092.91667 范例:2017年12月23日10:00:00至43092.91667

Below converts the date only, but I need to add the timestamp as well: 下面仅转换日期,但我还需要添加时间戳:

def convertDateToExcel(day, month, year) :
    offset = 693594
    itime = date(year,month,day)
    n = itime.toordinal()
    return (n - offset)

A prime example of me overthinking the problem :-) 我是一个过度思考问题的典型例子:-)

The obvious answer: 显而易见的答案:

   def convertDateToExcel(year, month, day, hour, minute, second) :
          offset = 693594
          itime = date(year,month,day)
          n = itime.toordinal()
          return (n - offset + (60*60*hour + 60*minute + second)/(24*60*60))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM