1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
/* Java SimpleDateFormat example. This Java SimpleDateFormat example describes how class is defined and being used in Java language. */ import java.text.SimpleDateFormat; import java.util.Date; public class JavaSimpleDateFormatExample{ public static void main(String args[]){ // Create Date object. Date date = new Date(); //Specify the desired date format String DATE_FORMAT = "MM/dd/yyyy"; //Create object of SimpleDateFormat and pass the desired date format. SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); /* Use format method of SimpleDateFormat class to format the date. */ System.out.println("Today is " + sdf.format(date) ); } } /* OUTPUT of the above given Java SimpleDateFormat Example would be : Today is 02/06/2005 */ |
Thanks a lot It ended my long search
/**
*
*/
package com.dateformat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
/**
* @author Nagaraju
*
*/
public class DateFormat {
/**
* @param args
*/
public static void main(String[] args) {
// Auto-generated method stub
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(“EEE MMM dd HH:mm:ss zzz yyyy”, Locale.US);
simpleDateFormat.setTimeZone(TimeZone.getTimeZone(“GMT”));
String todayGMT = simpleDateFormat.format(new Date());
System.out.println(todayGMT);
Date today = new Date();
System.out.println(today.toString());
}
}