new Date(String)

C

cmk128

Hi
The "Date d=new Date("2005/06/22") is deprecated, the java document
tell me we should use "DateFormat.parse(String)" method, but it is a
static method so we cannot use it in non-static method. How to fix
this?

thanks
from Peter ([email protected])
 
B

Bjorn Abelli

The "Date d = new Date("2005/06/22") is deprecated, the java document
tell me we should use "DateFormat.parse(String)" method, but it is a
static method so we cannot use it in non-static method. How to fix
this?

I think you've got it backwards in a few places...

'static' methods can definitely be used in non-static contexts.

There can be problems the other way around though...

But DateFormat.parse(String) isn't static at all. I guess you've got it
mixed up with Date.parse(String), which is static, but *also* deprecated.

So, here's an example (not tested, but should give a hint):

import java.text.SimpleDateFormat ;
import java.util.Date;

....

SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
Date d = sdf.parse("2005/06/22");



/// Bjorn A



Inviato da X-Privat.Org - Registrazione gratuita http://www.x-privat.org/join.php
 
C

cmk128

Bjorn Abelli 寫é“:
I think you've got it backwards in a few places...

'static' methods can definitely be used in non-static contexts.

There can be problems the other way around though...

But DateFormat.parse(String) isn't static at all. I guess you've got it
mixed up with Date.parse(String), which is static, but *also* deprecated.

So, here's an example (not tested, but should give a hint):

import java.text.SimpleDateFormat ;
import java.util.Date;

...

SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
Date d = sdf.parse("2005/06/22");



/// Bjorn A



Inviato da X-Privat.Org - Registrazione gratuita http://www.x-privat.org/join.php

thank you for your great solution
I double check it, DateFormat.parse is really static.Anyway thanks
again
from Peter
 
B

Bjorn Abelli

Bjorn Abelli 寫é"ï¼s
thank you for your great solution
I double check it, DateFormat.parse is really static.

I don't know where you have "double checked" it, and I hate to nitpick, but
as I said before, DateFormat.parse(String) is *not* static.

http://java.sun.com/j2se/1.5.0/docs/api/java/text/DateFormat.html#parse(java.lang.String)
Anyway thanks again

You're welcome.

/// Bjorn A



Inviato da X-Privat.Org - Registrazione gratuita http://www.x-privat.org/join.php
 
C

cmk128

ohhh, i thought only static method can reference from the claass name,
but it is not.
How can it be possible?
 
C

cmk128

sorry sorry.
Great mistake, cannot invoke it like this "DateFormat.parse ". Just a
mistake
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top