Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python datetime to XML Schema timestamp format

Tags:

python

xml

xsd

Is there an easy way to create a timestamp, in XML Schema format?

datetime.datetime.now() does not work.

.now(): 2012-02-17 09:52:35.033232

Desired: 2012-02-15T14:18:46.295-02:00

Looks pretty much the same, but fails on schema validation.

like image 955
joaoricardo000 Avatar asked Feb 17 '12 11:02

joaoricardo000


People also ask

Which of the following is the correct representation of date and time in XML schema?

The correct answer is A (xs:date) and C (xs:gMonthDay). These two are embedded simple types representing time and date under XML Schema.

What is datetime Tzinfo?

tzinfo is an abstract base class. It cannot be instantiated directly. A concrete subclass has to derive it and implement the methods provided by this abstract class. The instance of the tzinfo class can be passed to the constructors of the datetime and time objects.

How do I change the default date in XML?

If you want a fixed default date, you should be able to use the "defaultvalue" tag in your *-items. xml file. If you want to have a some kind of a dynamic default date (maybe with some business logic) you can use an interceptor.


1 Answers

>>> datetime.datetime.now(pytz.utc).isoformat()
'2012-02-17T11:58:44.789024+00:00'

>>> datetime.datetime.now(pytz.timezone('Europe/Paris')).isoformat()
'2012-02-17T13:00:10.885743+01:00'

apply your own time zone if needed.

like image 170
eumiro Avatar answered Sep 19 '22 12:09

eumiro