How do I convert a date/time to epoch time (unix time/seconds since 1970) in Perl?

前端 未结 13 2154
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-03 04:20

Given a date/time as an array of (year, month, day, hour, minute, second), how would you convert it to epoch time, i.e., the number of seconds since 1970-01-01 00:00:00 GMT?

13条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 04:49

    There are many Date manipulation modules on CPAN. My particular favourite is DateTime and you can use the strptime modules to parse dates in arbitrary formats. There are also many DateTime::Format modules on CPAN for handling specialised date formats, but strptime is the most generic.

提交回复
热议问题