Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Epoch to specific output

by atcroft (Abbot)
on Jan 02, 2014 at 18:07 UTC ( [id://1069000]=note: print w/replies, xml ) Need Help??


in reply to Epoch to specific output

This *seems* to do what you are asking, at least for my first test:

perl -MPOSIX -e 'my $t = time; print strftime("%m%d%H%M", gmtime $t);'
You could use localtime in place of gmtime, but then you would have to consider what you want to occur when there are DST (daylight saving time) changes.

Hope that helps.

Replies are listed 'Best First'.
Re^2: Epoch to specific output
by Anonymous Monk on Jan 02, 2014 at 18:47 UTC

    Your suggestion works well with a direct input for time. However, I was unable to substitute time with the $x variable.

    I was able to get it to work though with the following code:

    echo $x|perl -MPOSIX -e 'print strftime("%m%d%H%M", gmtime <stdin>)'

    Thank you everyone for your help!

      Pass your variable as an additional argument, use @ARGV to get it from inside the program:
      perl -MPOSIX -le'print strftime("%m%d%H%M", gmtime $ARGV[0])' "$x"
        Or just use shift:
        perl -MPOSIX -le 'print strftime("%m%d%H%M", gmtime shift)' "$x"
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1069000]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-26 01:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found