From: Brian E. <bm...@vi...> - 2002-02-20 22:23:11
|
Couple of things -- DateFormat is abstract and format is an instance (not class) method. Jython reports it as requiring 2-3 args because the first arg is the implicit "this". SimpleDateFormat is instantiable and you'll need to create an instance of it to call format: >>> from java.text import SimpleDateFormat >>> from java.util import Date >>> date = Date() >>> date Wed Feb 20 16:05:04 CST 2002 >>> sdf = SimpleDateFormat() >>> sdf.format(date) '2/20/02 4:05 PM' The Python documentation states strptime uses a default format of |"%a %b %d %H:%M:%S %Y"| (identical to ctime's formatting), so, while Jython doesn't have strptime, you could use strftime with that format (or ctime itself): >>> import time >>> time.strftime("%a %b %d %H:%M:%S %Y", time.localtime(time.time())) 'Wed Feb 20 16:17:28 2002' >>> time.ctime(time.time()) 'Wed Feb 20 16:20:26 2002' Mike Hostetler wrote: >Maybe I'm doing something dumb here -- I dunno. I'll honestly admit that >I know more about Python than Java . . > >I'm wanting to emulate something like the time.strpformat in the >CPython/Unix library. The closest I've found is the java.text.DateFormat class >in the Java standard library. I think I'm using it right, but I get a >very strange error: > >>>>from java.text import DateFormat >>>>date >>>> >'Wednesday February 20 12:06:17 CST 2002' > >>>>t = DateFormat.parse(date) >>>> >Traceback (innermost last): > File "<console>", line 1, in ? >TypeError: parse(): expected 2-3 args; got 1 > >According to the Java API docs, DateFormat.parse only requires 1-2 args: > >parse >public Date parse(String text) > throws ParseException > >parse >public abstract Date parse(String text, ParsePosition pos) > >Anyone have any suggestions?? > >-- mikeh > > >_______________________________________________ >Jython-users mailing list >Jyt...@li... >https://lists.sourceforge.net/lists/listinfo/jython-users > |