How to convert date to timestamp Perl? Use Date::Parse to convert normal date string to epoch timestamp. Date::Parse provides two routines for parsing date strings into time values.

str2time(DATE [, ZONE])

str2time parses DATE and returns a Unix time value or undef upon failure. ZONE, if given, specifies the timezone to assume when parsing if the date string does not specify a timezone.

strptime(DATE [, ZONE])

strptime takes the same arguments as str2time but returns an array of values ($ss,$mm,$hh,$day,$month,$year,$zone). Elements are only defined if they could be extracted from the date string. The $zone element is the timezone offset in seconds from GMT. An empty array is returned upon failure.

Convert date to timestamp Perl – Source code

use Date::Parse;

print str2time("11/22/2016 11:50AM");

Output:

1479811800

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Sign In

Register

Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.