Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 41481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:11:15+00:00 2026-05-10T15:11:15+00:00

Given a date/time as an array of (year, month, day, hour, minute, second), how

  • 0

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?

Bonus question: If given the date/time as a string, how would you first parse it into the (y,m,d,h,m,s) array?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T15:11:16+00:00Added an answer on May 10, 2026 at 3:11 pm

    This is the simplest way to get unix time:

    use Time::Local; timelocal($second,$minute,$hour,$day,$month-1,$year); 

    Note the reverse order of the arguments and that January is month 0. For many more options, see the DateTime module from CPAN.

    As for parsing, see the Date::Parse module from CPAN. If you really need to get fancy with date parsing, the Date::Manip may be helpful, though its own documentation warns you away from it since it carries a lot of baggage (it knows things like common business holidays, for example) and other solutions are much faster.

    If you happen to know something about the format of the date/times you’ll be parsing then a simple regular expression may suffice but you’re probably better off using an appropriate CPAN module. For example, if you know the dates will always be in YMDHMS order, use the CPAN module DateTime::Format::ISO8601.


    For my own reference, if nothing else, below is a function I use for an application where I know the dates will always be in YMDHMS order with all or part of the ‘HMS’ part optional. It accepts any delimiters (eg, ‘2009-02-15’ or ‘2009.02.15’). It returns the corresponding unix time (seconds since 1970-01-01 00:00:00 GMT) or -1 if it couldn’t parse it (which means you better be sure you’ll never legitimately need to parse the date 1969-12-31 23:59:59). It also presumes two-digit years XX up to ’69’ refer to ’20XX’, otherwise ’19XX’ (eg, ’50-02-15′ means 2050-02-15 but ’75-02-15′ means 1975-02-15).

    use Time::Local;  sub parsedate {    my($s) = @_;   my($year, $month, $day, $hour, $minute, $second);    if($s =~ m{^\s*(\d{1,4})\W*0*(\d{1,2})\W*0*(\d{1,2})\W*0*                  (\d{0,2})\W*0*(\d{0,2})\W*0*(\d{0,2})}x) {     $year = $1;  $month = $2;   $day = $3;     $hour = $4;  $minute = $5;  $second = $6;     $hour |= 0;  $minute |= 0;  $second |= 0;  # defaults.     $year = ($year<100 ? ($year<70 ? 2000+$year : 1900+$year) : $year);     return timelocal($second,$minute,$hour,$day,$month-1,$year);     }   return -1; } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 112k
  • Answers 112k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You could use something like the following function selectFromArray($prefix="", $productArray=array())… May 11, 2026 at 9:58 pm
  • Editorial Team
    Editorial Team added an answer I would suggest finding the elements as few times as… May 11, 2026 at 9:58 pm
  • Editorial Team
    Editorial Team added an answer Try xcopy /Y $(ProjectDir)Resources\*.* $(TargetDir)Resources\ That is probably the most… May 11, 2026 at 9:58 pm

Related Questions

A niave beginners question about database design. I have an app managing some logger
Is there an existing solution to create a regular expressions dynamically out of a
I was given a database design which stores information about an organization and any
I'm experimenting with a personal finance application, and I'm thinking about what approach to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.