Btw, since you did not use any quotes it is actually an equivalent to localtime(1971)Ĭorrect function argument should be a number of non-leap seconds since your system Epoch, normally 00:00:00 GMT, January 1, 1970. Localtime() makes as much (or as little) sense as localtime('boo-foo'). Your problem is incorrect localtime argument. Is there any other alternative to using strftime()? The perl strftime documentation refers the reader to the local strftime man page for conversion specifiers, while others (Ive looked at python, ruby and php) give a list of available conversion specifiers. I read in some previous post that this might be because of the way Unix interprets the dates and strftime function parses it. Print POSIX::strftime('%m/%d/%Y %H:%M:%S',localtime()) īasically the output intended is like this: When we use localtime () method in Perl, the current date and time are shown we won’t need any arguments to be passing in the method. Very often I need to add a timestamp to some log file, or create a file based on a the current date. Local Specifiers GMT Specifiers Perl Displaying Date and Time Sometimes we need to display a date or time in different formats. There are two types of specifiers, one is for local time and other is for gmt time zone. You mention in your answer POSIX::strptime which is great if your platform supports it. The Perl POSIX strftime () function is used to format date and time with the specifiers preceded with () sign. However, now that I understand your question is how to go from a strftime formatted string to a time in general, that approach is bound to be cumbersome. The issue is no matter what is passed in the 'Date' field during the workflow the following code in the IPL interprets it as only. One option is to parse the numbers using a regular expression and then use Time::Local. Timestamp can be created by creating a DateTime object and then calling the now constructor. mwp at 1:50 Add a comment 3 I would recommend using Time::Piece for this job - its core in perl. Data displayed by timestamp is sometimes accurate to a fraction of seconds. To expound, localtime () takes the epoch and returns a string (or date parts array) representing the time in your local timezone gmtime () takes the epoch and returns a string (or date parts array) representing the time in UTC. I am trying to resolve an issue in previously written code. A timestamp in Perl is used to display the current Date and Time of the day.
0 Comments
Leave a Reply. |