You can format output date using the strftime method within Time::Piece - this is merely the default output. That's not good practice - at the very least you should use some way of discovering 'current year' automatically - but bear in mind that at some points in the year, this will Just Break. I've gone for the easy road of just inserting 2015. Data displayed by timestamp is sometimes accurate to a fraction of seconds. Note though - your timestamps are ambiguous because they omit the year. A timestamp in Perl is used to display the current Date and Time of the day. Time::Piece->strptime( "$M $D $T 2015", "%b %d %H:%M:%S %Y" ) This can be made clearer by splitting up the statements. Logically, you use the strptime () function from POSIX. You can replace say with print if you dont require a new line at the end of the output. Here's an example: writesecs (stat (file)) 9 printf 'file s updated at s ', file, scalar localtime (writesecs) If you prefer something more. Local: echo 1357810480 perl -nE say scalar localtime. To retrieve the raw'' time in seconds since the epoch, you would call the stat function, then use localtime (), gmtime (), or POSIX::strftime () to convert this into human-readable form. I found this very useful in my Bash scripts: UTC: echo 1357810480 perl -nE say scalar gmtime. Generating the time corresponding to a given date/time value is rather less easy. To add to the answer, you can also replace localtime with gmtime in order to get the UTC time. Generating the current time in Perl is rather easy: perl -e print time, 'n'. If you wish to use perl to create a date/time stamp, well, there are a few gotchas. Time::Piece is one of the better options for doing this #!/usr/local/bin/perl A Unix time stamp is the number of seconds since that time - not accounting for leap seconds. However sorting by time stamp requires converting the 'text' representation to an actual time. A hash is good for coalescing duplicates.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |