Example usage for java.text DateFormatSymbols DateFormatSymbols

List of usage examples for java.text DateFormatSymbols DateFormatSymbols

Introduction

In this page you can find the example usage for java.text DateFormatSymbols DateFormatSymbols.

Prototype

public DateFormatSymbols() 

Source Link

Document

Construct a DateFormatSymbols object by loading format data from resources for the default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:Main.java

public static void main(String[] args) {
    String[] months = new DateFormatSymbols().getMonths();
    for (int i = 0; i < months.length; i++) {
        String month = months[i];
        System.out.println("month = " + month);
    }/*  w  w  w .  j  a v  a 2 s .  com*/

}

From source file:Main.java

public static void main(String[] args) {
    String[] weekdays = new DateFormatSymbols().getWeekdays();
    for (int i = 0; i < weekdays.length; i++) {
        String weekday = weekdays[i];
        System.out.println("weekday = " + weekday);
    }/*from  ww w  . j a v  a2s.com*/

}

From source file:MainClass.java

public static void main(String[] args) {
    String[] weekdays = new DateFormatSymbols().getWeekdays(); // Get day names
    for (String s : weekdays) {
        System.out.println(s);//  w  w  w  . j  av  a  2 s .c  o  m
    }
}

From source file:Main.java

public static void main(String[] args) {
    String[] shortMonths = new DateFormatSymbols().getShortMonths();
    for (int i = 0; i < shortMonths.length; i++) {
        String shortMonth = shortMonths[i];
        System.out.println("shortMonth = " + shortMonth);
    }/*from w w w  .  jav a 2 s  .co m*/
}

From source file:Main.java

public static void main(String[] args) {
    String[] shortWeekdays = new DateFormatSymbols().getShortWeekdays();
    for (int i = 0; i < shortWeekdays.length; i++) {
        String shortWeekday = shortWeekdays[i];
        System.out.println("shortWeekday = " + shortWeekday);
    }/* www  . j a  va2  s  .  com*/
}

From source file:Main.java

public static void main(String[] args) {
    String dayNames[] = new DateFormatSymbols().getWeekdays();
    Calendar date2 = Calendar.getInstance();
    System.out.println("Today is a " + dayNames[date2.get(Calendar.DAY_OF_WEEK)]);
}

From source file:Main.java

public static void main(String[] args) {
    List list = new LinkedList();

    DateFormatSymbols dfs = new DateFormatSymbols();
    String[] months = dfs.getMonths();
    for (int i = 0; i < months.length; i++) {
        String month = months[i];
        list.add(month);//from   w ww.  j a  v  a  2  s .  c  o  m
    }

    Collections.sort(list);
    System.out.println("Month Names = " + list);
    int index = Collections.binarySearch(list, "October");
    if (index > 0) {
        System.out.println("Found at index = " + index);
        String month = (String) list.get(index);
        System.out.println("Month = " + month);
    }
}

From source file:MainClass.java

public static void main(String[] args) {

    GregorianCalendar birthdate = new GregorianCalendar(1999, 1, 1);
    GregorianCalendar today = new GregorianCalendar(); // Today's date
    GregorianCalendar birthday = new GregorianCalendar(today.get(YEAR), birthdate.get(MONTH),
            birthdate.get(DATE));//from   www .  ja  v a 2 s  .co  m
    int age = today.get(today.YEAR) - birthdate.get(YEAR);
    String[] weekdays = new DateFormatSymbols().getWeekdays(); // Get day names
    System.out.println("You were born on a " + weekdays[birthdate.get(DAY_OF_WEEK)]);
    System.out.println("This year you " + (birthday.after(today) ? " will be " : "are ") + age + " years old.");
    System.out
            .println("In " + today.get(YEAR) + " your birthday " + (today.before(birthday) ? "will be" : "was")
                    + " on a " + weekdays[birthday.get(DAY_OF_WEEK)] + ".");
}

From source file:Main.java

public static void main(String[] args) {
    String[] newMonths = { "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC" };
    String[] newShortMonths = { "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov",
            "dec" };
    String[] newWeekdays = { "", "Monday", "Tuesday", "Webnesday", "Thursday", "Friday", "Saturaday",
            "Sunday" };
    String[] shortWeekdays = { "", "monday", "tuesday", "webnesday", "thursday", "friday", "saturaday",
            "sunday" };

    DateFormatSymbols symbols = new DateFormatSymbols();
    symbols.setMonths(newMonths);//  w  w  w  . jav  a2  s  .  co  m
    symbols.setShortMonths(newShortMonths);
    symbols.setWeekdays(newWeekdays);
    symbols.setShortWeekdays(shortWeekdays);

    DateFormat format = new SimpleDateFormat("dd MMMM yyyy", symbols);
    System.out.println(format.format(new Date()));

    format = new SimpleDateFormat("dd MMM yyyy", symbols);
    System.out.println(format.format(new Date()));

    format = new SimpleDateFormat("EEEE, dd MMM yyyy", symbols);
    System.out.println(format.format(new Date()));

    format = new SimpleDateFormat("E, dd MMM yyyy", symbols);
    System.out.println(format.format(new Date()));
}

From source file:CalendarTest.java

public static void main(String[] args) {
    // construct d as current date
    GregorianCalendar d = new GregorianCalendar();

    int today = d.get(Calendar.DAY_OF_MONTH);
    int month = d.get(Calendar.MONTH);

    // set d to start date of the month
    d.set(Calendar.DAY_OF_MONTH, 1);

    int weekday = d.get(Calendar.DAY_OF_WEEK);

    // get first day of week (Sunday in the U.S.)
    int firstDayOfWeek = d.getFirstDayOfWeek();

    // determine the required indentation for the first line
    int indent = 0;
    while (weekday != firstDayOfWeek) {
        indent++;/*from   ww  w.j a  v a 2  s  . co m*/
        d.add(Calendar.DAY_OF_MONTH, -1);
        weekday = d.get(Calendar.DAY_OF_WEEK);
    }

    // print weekday names
    String[] weekdayNames = new DateFormatSymbols().getShortWeekdays();
    do {
        System.out.printf("%4s", weekdayNames[weekday]);
        d.add(Calendar.DAY_OF_MONTH, 1);
        weekday = d.get(Calendar.DAY_OF_WEEK);
    } while (weekday != firstDayOfWeek);
    System.out.println();

    for (int i = 1; i <= indent; i++)
        System.out.print("    ");

    d.set(Calendar.DAY_OF_MONTH, 1);
    do {
        // print day
        int day = d.get(Calendar.DAY_OF_MONTH);
        System.out.printf("%3d", day);

        // mark current day with *
        if (day == today)
            System.out.print("*");
        else
            System.out.print(" ");

        // advance d to the next day
        d.add(Calendar.DAY_OF_MONTH, 1);
        weekday = d.get(Calendar.DAY_OF_WEEK);

        // start a new line at the start of the week
        if (weekday == firstDayOfWeek)
            System.out.println();
    } while (d.get(Calendar.MONTH) == month);
    // the loop exits when d is day 1 of the next month

    // print final end of line if necessary
    if (weekday != firstDayOfWeek)
        System.out.println();
}