I would like to take a time stamp (e.g. 1263531246) and convert it to a string representation suitable for output to an XML file in an attribute field conforming to xs:dateTime. xs:dateTime expects something like:
2002-05-30T09:30:10-06:00
Ideally, I would use the form of output that includes offset from UTC (as above). In this project, I am constrained to use Perl. Any suggestions?
This works on Linux:
$ perl -MPOSIX -e 'print POSIX::strftime("%Y-%m-%dT%H:%M:%S%z\n", localtime)' 2010-02-04T17:37:43-0500On Windows, with ActiveState Perl, it prints:
Using DateTime:
I get the correct string on Windows as well:
I believe Date::Format is much lighter weight module:
Output: