Formatting date in default formats using DateFormat
import java.text.DateFormat;
import java.util.Date;
public class Main {
public static void main(String[] args) {
Date date = new Date();
String strDate = DateFormat.getDateInstance(DateFormat.SHORT).format(date);
System.out.println("Short:"+strDate);
strDate = DateFormat.getDateInstance(DateFormat.MEDIUM).format(date);
System.out.println("Medium:"+strDate);
strDate = DateFormat.getDateInstance(DateFormat.LONG).format(date);
System.out.println("Long:"+strDate);
strDate = DateFormat.getDateInstance(DateFormat.FULL).format(date);
System.out.println("Full:"+strDate);
}
}
The output:
Short:11/14/10
Medium:Nov 14, 2010
Long:November 14, 2010
Full:Sunday, November 14, 2010
Home
Java Book
Essential Classes
Java Book
Essential Classes
SimpleDateFormat:
- SimpleDateFormat class introduction
- SimpleDateFormat formats date, day,
- Add AM PM to time format using SimpleDateFormat
- Formatting date in default formats using DateFormat
- Formatting day using SimpleDateFormat
- Formatting day of week using SimpleDateFormat
- Formatting hour using SimpleDateFormat
- Formatting hour using SimpleDateFormat: k
- Formatting Minutes using SimpleDateFormat
- Formatting month using SimpleDateFormat
- Formatting seconds using SimpleDateFormat
- Formatting TimeZone using SimpleDateFormat
- Formatting year using SimpleDateFormat
- Use various format
- Convert date string from one format to another format using SimpleDateFormat