Source

jython-db4o / db4o / util.py

__author__ = 'Sean Summers <SeanSummers@gmail.com>'

import java.util.Date
import java.util.GregorianCalendar
import javax.xml.bind.DatatypeConverter

def encode_jud(o):
    if isinstance(o, java.util.Date):
        return toISO8601(o)
    raise TypeError(repr(o) + ' is not JSON serializable')

def toISO8601(javaDate):
    cal = java.util.GregorianCalendar.getInstance()
    cal.setTime(javaDate)
    return javax.xml.bind.DatatypeConverter.printDateTime(cal)

def fromISO8601(ISO8601date):
    return javax.xml.bind.DatatypeConverter.parseDateTime(ISO8601date).getTime()