HOW to convert date string to sec?

Discussion in 'Perl Misc' started by news.hinet.net, Jul 22, 2004.

  1. if i have a date string like 200407221405000 .
    how to convert the string to sec from 1971/1/1 like time()?
    news.hinet.net, Jul 22, 2004
    #1
    1. Advertising

  2. "news.hinet.net" <> wrote in news:cdnbdt$n0a$1
    @netnews.hinet.net:

    >
    > if i have a date string like 200407221405000 .
    > how to convert the string to sec from 1971/1/1 like time()?


    How about looking at the various Date:: modules on CPAN.

    By the way, are you sure you have read

    perldoc -f time

    --
    A. Sinan Unur
    d
    (remove '.invalid' and reverse each component for email address)
    A. Sinan Unur, Jul 22, 2004
    #2
    1. Advertising

  3. In article <cdnbdt$n0a$>,
    "news.hinet.net" <> wrote:

    > if i have a date string like 200407221405000 .
    > how to convert the string to sec from 1971/1/1 like time()?


    sub utc2seconds {
    my $utc = shift @_;
    my $YYYY = substr($utc,0,4);
    my $MM = substr($utc,4,2);
    my $DD = substr($utc,6,2);
    my $hh = substr($utc,8,2);
    my $mm = substr($utc,10,2);
    my $ss = substr($utc,12,2);
    return timegm($ss,$mm,$hh,$DD,$MM,$YYYY);
    }
    ....
    my $seconds = utc2seconds(200407221405000);
    Dangerous Lunatic, Jul 22, 2004
    #3
  4. i dont want to use module.
    because i must install those module


    "A. Sinan Unur" <> ¦b¶l¥ó
    news:Xns952DEF0E762FEasu1cornelledu@132.236.56.8 ¤¤¼¶¼g...
    > "news.hinet.net" <> wrote in news:cdnbdt$n0a$1
    > @netnews.hinet.net:
    >
    > >
    > > if i have a date string like 200407221405000 .
    > > how to convert the string to sec from 1971/1/1 like time()?

    >
    > How about looking at the various Date:: modules on CPAN.
    >
    > By the way, are you sure you have read
    >
    > perldoc -f time
    >
    > --
    > A. Sinan Unur
    > d
    > (remove '.invalid' and reverse each component for email address)
    >
    news.hinet.net, Jul 22, 2004
    #4
  5. timegm is perl build-in function??


    "Dangerous Lunatic" <> ¦b¶l¥ó
    news:p ¤¤¼¶¼g...
    > In article <cdnbdt$n0a$>,
    > "news.hinet.net" <> wrote:
    >
    > > if i have a date string like 200407221405000 .
    > > how to convert the string to sec from 1971/1/1 like time()?

    >
    > sub utc2seconds {
    > my $utc = shift @_;
    > my $YYYY = substr($utc,0,4);
    > my $MM = substr($utc,4,2);
    > my $DD = substr($utc,6,2);
    > my $hh = substr($utc,8,2);
    > my $mm = substr($utc,10,2);
    > my $ss = substr($utc,12,2);
    > return timegm($ss,$mm,$hh,$DD,$MM,$YYYY);
    > }
    > ...
    > my $seconds = utc2seconds(200407221405000);
    news.hinet.net, Jul 22, 2004
    #5
  6. news.hinet.net

    Tore Aursand Guest

    On Thu, 22 Jul 2004 11:13:32 +0800, news.hinet.net wrote:
    > if i have a date string like 200407221405000


    What kind if date is that? 2004-07-22 14:05:000? I guess you added a '0'
    too much at the end there.

    > how to convert the string to sec from 1971/1/1 like time()?


    First of all, it's seconds since January 1st, 1970 you want. Secondly,
    you don't need to install an extra module (if you have a fairly up-to-date
    Perl installation); the Time::Local is there for you;

    perldoc Time::Local


    --
    Tore Aursand <>
    "To cease smoking is the easiset thing I ever did. I ought to know,
    I've done it a thousand times." (Mark Twain)
    Tore Aursand, Jul 22, 2004
    #6
  7. news.hinet.net

    Joe Smith Guest

    news.hinet.net wrote:

    > i dont want to use module.
    > because i must install those module


    How about *LOOKING* at a module from CPAN.
    As in look at the source code and see how it's done.
    -Joe
    Joe Smith, Jul 22, 2004
    #7
  8. "news.hinet.net" <> wrote in news:cdnirk$86m$1
    @netnews.hinet.net:

    [ top-posting fixed: please don't do that ]

    > "A. Sinan Unur" <> ¦b¶l¥ó
    > news:Xns952DEF0E762FEasu1cornelledu@132.236.56.8 ¤¤¼¶¼g...


    >> "news.hinet.net" <> wrote in news:cdnbdt$n0a$1
    >> @netnews.hinet.net:
    >>
    >> >
    >> > if i have a date string like 200407221405000 .
    >> > how to convert the string to sec from 1971/1/1 like time()?

    >>
    >> How about looking at the various Date:: modules on CPAN.


    > i dont want to use module.
    > because i must install those module


    Have you read:

    perldoc -q own

    I realize using Time::Local is the answer to your question but looking at
    the FAQ above is a good idea.

    --
    A. Sinan Unur
    d
    (remove '.invalid' and reverse each component for email address)
    A. Sinan Unur, Jul 22, 2004
    #8
  9. news.hinet.net wrote:

    >
    > if i have a date string like 200407221405000 .
    > how to convert the string to sec from 1971/1/1 like time()?


    You may also use the HTTP::Date module which almost answers your needs
    it is also based on Time::Local.

    --
    Johnny "gandalf" Brasseur (http://www.perlone.org)
    Johnny \Gandalf\ Brasseur, Jul 22, 2004
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. happyinst
    Replies:
    1
    Views:
    459
    happyinst
    Jul 10, 2003
  2. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,244
    Michael Borgwardt
    May 30, 2004
  3. wgan
    Replies:
    7
    Views:
    590
    Roedy Green
    Jul 8, 2004
  4. Summu82
    Replies:
    5
    Views:
    861
    Richard Heathfield
    Jun 7, 2006
  5. Replies:
    8
    Views:
    781
    Boris
    May 1, 2007
Loading...

Share This Page