[NCLUG] perl datestring to timestamp conversion ?

Gabriel Somlo somlo at acns.colostate.edu
Mon Jan 10 15:47:02 MST 2005


On Mon, Jan 10, 2005 at 02:06:26PM -0800, Matt Taggart wrote:
> 
> perl has localtime and gmtime functions. They may not be as cool as the posix 
> module you're using, but I bet they'll exist for any version of perl. man 
> perlfunc(1).
> 

Right. localtime and gmtime convert a numerical timestamp (seconds
since the epoch) into a structure (or was it a string?) containing
separate values for year, month, ... , minute, second. local generates
numbers for the localtime representation of the timestamp, and gmtime
for the utc representation.


I need to convert things in the opposite direction. Given numbers for
year, month, etc, all the way to the second, *and* a flag that says
whether this is local or utc, I need go generate the timestamp.

mktime in the posix module does this, but only for localtime. There's
no flag for whether you want local or utc, it just does local by
default.

Jake Edge said to try setting the TZ env variable hoping to trick
mktime
into doing utc or local depending on the $TZ value. I think that's 
probably what I'll do if it ends up working -- still have to try that 
out and see, though :)

Thanks a ton for all your ideas,

Gabriel




More information about the NCLUG mailing list