I have a date time displayed as 06 August 2012 21:02:00
and need to convert it to a Unix timestamp using Perl.
Asked
Active
Viewed 1.4k times
-2

Borodin
- 126,100
- 9
- 70
- 144

user1349704
- 19
- 1
- 2
- 2
-
10It doesn't matter to me if it's basic. What matters to me is that the OP didn't show any code to demonstrate what he has tried, didn't explain how that attempt failed, didn't show any research, didn't elaborate on any thoughts he already has of how to solve it himself first, and essentially showed no effort. Basic is fine. But this isn't a code-writing service, and a little effort needs to go into questions to show that we're not being treated as such. – DavidO Aug 06 '12 at 21:36
-
@pavel - basic questions are not against SO rules. – DVK Aug 07 '12 at 00:56
-
Duplicate? http://stackoverflow.com/questions/95492/how-do-i-convert-a-date-time-to-epoch-time-aka-unix-time-seconds-since-1970?rq=1 – DVK Aug 07 '12 at 00:58
-
I am surprised at the closure of this question, especially from @briandfoy. A call of *duplicate* may have been appropriate, but *not constructive* is bizarre. – Borodin Dec 02 '14 at 09:38
2 Answers
7
If you want to stay with core modules, use Time::Piece
(available in Perl 5.10 on):
use Time::Piece;
my $t = Time::Piece->strptime(shift,"%d %B %Y %H:%M:%S");
print $t->epoch, "\n";
./mypl "06 August 2012 21:02:00"
1344286920

JRFerguson
- 7,426
- 2
- 32
- 36
6
use Date::Parse;
print str2time('06 August 2012 21:02:00');

Borodin
- 126,100
- 9
- 70
- 144

Roberto Navarro
- 948
- 4
- 16