Search code examples
pythonjythondate-conversion

jython date conversion


Given a string as below, I need to convert:

1 Dec 2008 06:43:00 +0100

to

MM/DD/YYYY HH:MM:SSAM

using jython what is the best way to do this?


Solution

  • I don't have jython handy, but I'd expect something like this to work:

    import java
    sdf = java.text.SimpleDateFormat
    
    fmt_in = sdf('d MMM yyyy HH:mm:ss Z')
    fmt_out = sdf('MM/dd/yyyy HH:mm:ssaa')
    
    fmt_out.format(fmt_in.parse(time_str))