LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-06-2017, 07:45 AM   #1
say_hi_ravi
Member
 
Registered: Jan 2008
Posts: 75

Rep: Reputation: 15
Convert any given time to epoch time in Perl


Hi,

Any idea in perl, how can I convert a date in the format "2016-11-20 12:42:40" to epoch time.

Thanks.
Ravi
 
Old 02-06-2017, 07:54 AM   #2
say_hi_ravi
Member
 
Registered: Jan 2008
Posts: 75

Original Poster
Rep: Reputation: 15
Hi Folks,

Just figured out..

Quote:
/usr/bin/perl -MDate::Parse -e 'print Date::Parse::str2time("2017-02-11 15:16:48"), "\n"'
Regards,
Ravi
 
Old 02-06-2017, 08:14 AM   #3
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,636
Blog Entries: 4

Rep: Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933
In the Perl language there are literally dozens of CPAN modules that can do anything you might imagine to do with dates and times.

(As noted below: some are built-in.)

Last edited by sundialsvcs; 02-14-2017 at 05:27 PM.
 
Old 02-06-2017, 08:14 AM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,292
Blog Entries: 3

Rep: Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718
There's also Date::Calc if you need to further manipulate, compare, or calculate dates.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how to get epoch time in fraction vdx Programming 4 06-10-2011 09:36 AM
Convert a given date to epoch time and vice versa. coders123 Programming 2 01-05-2011 10:44 PM
How to : Convert the epoch time to standard time with bash avklinux AIX 1 02-26-2009 07:21 PM
PHP Time before Unix Epoch? wh33t Programming 2 08-29-2006 01:32 PM
Epoch time the other way! michedlp Programming 0 04-25-2004 03:51 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration