Как преобразовать Строковый объект датировать объект? [дубликат]

10
задан Suresh Chaganti 8 November 2011 в 05:41
поделиться

7 ответов

    SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
    Date date = dateFormat.parse("1.1.2001");

For details refer to: SimpleDateFormat documentation

21
ответ дан 3 December 2019 в 13:47
поделиться

Date-to-String conversion is a relatively complex parsing operation, not something you can do with a simple cast as you are trying.

You'll have to use a DateFormat. It can be as simple as:

Date d = DateFormat.getDateInstance().parse("09/10/2009");

But this changes the expected date format depending on the locale settings of the machine it's running on. If you have a specific date format, you can use SimpleDateFormat:

Date d = new SimpleDateFormat("d MMM yyyy HH:mm").parse("4 Jul 2001 12:08");

Note that the parse method will always expect one specific format, and will not try to guess what could be meant if it receives a different format.

9
ответ дан 3 December 2019 в 13:47
поделиться

See Sun's Java tutorial and the class SimpleDateFormat

4
ответ дан 3 December 2019 в 13:47
поделиться

java.text.SimpleDateFormat that extends java.text.DateFormat abstract class.

 DateFormat MYDate = new SimpleDateFormat("dd/MM/yyyy"); 
 Date today = MYDate.parse("09/10/2009");  
3
ответ дан 3 December 2019 в 13:47
поделиться

Use a SimpleDateFormat with a format string, which matches your actual format:

    SimpleDateFormat sdf = 
        new SimpleDateFormat("yyyy-MM-dd");
    Date d = sdf.parse("2009-10-09"); 
3
ответ дан 3 December 2019 в 13:47
поделиться

you should parse the string with the SimpleDateFormat class

1
ответ дан 3 December 2019 в 13:47
поделиться

use

Date date = DateFormat.getInstance.parse( dateString );
0
ответ дан 3 December 2019 в 13:47
поделиться
Другие вопросы по тегам:

Похожие вопросы: