Current location - Education and Training Encyclopedia - Resume - String date in Java format
String date in Java format
Parcel? Testing;

Import? Java . text . simple date format;

Import? Java . util . date;

Public? Class? DateStyle? {

Public? Static electricity Invalid? main(String[]? args)? {

SimpleDateFormat? dateformat 1? =? New? Simple date format (

" yyyymmdd hhmmss ");

Dating? Date = New? date();

date . setyear(2065 438+04- 1900);

date . set month(3- 1);

date . set date(29);

date . sethours( 19);

date . set minutes( 13);

date . set seconds(0);

String? a 1? =? Dateformat 1.format (date);

System.out.println ("time 2:"? +? a 1);

}

} effect:

2: 20140329191300. I hope I can help you.

Or because that method is out of date, you can use the calendar method, the code is as follows:

Parcel? Testing;

Import? Java . text . simple date format;

Import? Java.util calendar;

Import? Java . util . date;

Public? Class? DateStyle? {

Public? Static electricity Invalid? main(String[]? args)? {

SimpleDateFormat? dateformat 1? =? New? simple date format(" yyyymmdd hhmmss ");

Calendar? c? =? dateformat 1 . get calendar();

c.set(20 13,? 14,? 29,? 19,? 13,? 0);

Dating? d? =? c . gettime();

system . out . println(d);

String? a 1? =? date format 1 . format(d);

System.out.println ("time 2:"? +? a 1);

}

} effect:

Sat? Mar? 29? 19: 13:00? CST? 20 14

Time 2: 20140329191300, hope to adopt.