![]() Of course, then you can also do: print localtime(time) -> epoch Īnd do without all the fuss of converting back and forth. Note - Time::Piece overloads localtime so you can actually use it (fairly) transparently. Print localtime(time) -> strftime ( "%Y-%m-%d %H:%M:%S" ) How do I get a file's timestamp in perl If you want to retrieve the time at which the file was last read, written, or had its meta-data (owner, etc) changed, you use the -M, -A, or -C filetest operations as documented in the perlfunc manpage. You would probably be better off instead using Time::Piece and strftime to get a fixed format: Let's look at a couple of short examples to see how this works. Solution: Use the Perl stat function to get this information. Problem: Using Perl, you need to determine the last time a file was accessed (read) or updated (modified). This is the usual format used in American dates. Last updated: JHow to use the Perl stat function. When both the month and the date are specified in the date as numbers they are always parsed assuming that the month number comes before the date. That's probably why str2time is doing odd things - because it makes certain assumptions about formats that don't always apply. If you do it in a scalar context, it returns a string denoting the time: print "".localtime(time) īut note - that might vary somewhat depending on your current locale. 04-01-2008 biswajeet. (Which you can use without needing to parse). (In days, so you'll have to multiply up).īut if you really want to take the time and convert it back again - you'll need to look at how localtime(time) returns the result.īecause localtime is being evaluated in a list context, and so returning an array of values. Or perhaps better yet -M which tells you how long ago a file was modified. What is epoch time The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since Janu(midnight UTC/GMT), not counting leap seconds (in ISO 8601: ). On the NT side, you have a perl script which reads this file and calls the utime. You're doing something bizarre here - localtime(time) takes - the epoch time ( time) and converts it to a string. We call this file, TimeStamp.txt and transfer it to the same directory.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |