Below example is to just understand the syntax of DateFormat and Calender in Java.
package com.evaluatethecode;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
public class DateExampleJava6 {
public static void main(String[] args) {
DateFormat etcDFJpn = DateFormat.getDateInstance(DateFormat.LONG,
Locale.JAPAN);
DateFormat etcDFUs = DateFormat.getDateInstance(DateFormat.LONG,
Locale.US);
DateFormat etcDFUk = DateFormat.getDateInstance(DateFormat.LONG,
Locale.UK);
DateFormat etcDFGrmn = DateFormat.getDateInstance(DateFormat.LONG,
Locale.GERMAN);
Date etcDate = new Date();
System.out.println(etcDFJpn.format(etcDate));
System.out.println(etcDFUs.format(etcDate));
System.out.println(etcDFUk.format(etcDate));
System.out.println(etcDFGrmn.format(etcDate));
Calendar etcCal = Calendar.getInstance();
etcCal.set(Calendar.YEAR, 2009);
etcCal.set(Calendar.MONTH, 0);
etcCal.set(Calendar.DAY_OF_MONTH, 1);
etcDFJpn.setCalendar(etcCal);
System.out.println(etcCal.getTime());
}
}
Output:
2023/01/05
January 5, 2023
05 January 2023
5. Januar 2023
Thu Jan 01 01:36:20 IST 2009
No comments:
Post a Comment