Example usage for java.util Calendar LONG

List of usage examples for java.util Calendar LONG

Introduction

In this page you can find the example usage for java.util Calendar LONG.

Prototype

int LONG

To view the source code for java.util Calendar LONG.

Click Source Link

Document

A style specifier for #getDisplayName(int,int,Locale) getDisplayName and #getDisplayNames(int,int,Locale) getDisplayNames equivalent to #LONG_FORMAT .

Usage

From source file:NavigableMapSample.java

public static void main(String args[]) {
    Calendar now = Calendar.getInstance();
    Locale locale = Locale.getDefault();

    Map<String, Integer> names = now.getDisplayNames(Calendar.DAY_OF_WEEK, Calendar.LONG, locale);
    NavigableMap<String, Integer> nav = new TreeMap<String, Integer>(names);
    System.out.printf("Whole list:%n%s%n", nav);
    System.out.printf("Key ceiling after Sunday: %s%n", nav.ceilingKey("Sunday"));
}

From source file:NavigableMapSample.java

public static void main(String args[]) {
    Calendar now = Calendar.getInstance();
    Locale locale = Locale.getDefault();

    Map<String, Integer> names = now.getDisplayNames(Calendar.DAY_OF_WEEK, Calendar.LONG, locale);
    NavigableMap<String, Integer> nav = new TreeMap<String, Integer>(names);
    System.out.printf("Whole list:%n%s%n", nav);
    System.out.printf("First key: %s\tFirst entry: %s%n", nav.firstKey(), nav.firstEntry());
}

From source file:Main.java

public static void main(String[] args) {

    Calendar now = Calendar.getInstance();
    Locale locale = Locale.getDefault();

    // call the getdisplaynames method
    Map<String, Integer> representations = now.getDisplayNames(Calendar.DAY_OF_WEEK, Calendar.LONG, locale);

    NavigableMap<String, Integer> navMap = new TreeMap<String, Integer>(representations);

    // print the results
    System.out.printf("Whole list:%n%s%n", navMap);
}

From source file:Main.java

public static String getDateDisplay(Calendar cal) {
    return cal.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.US) + " " + cal.get(Calendar.DATE) + ", "
            + cal.get(Calendar.YEAR);
}

From source file:Main.java

public static String getMonthStringFromDate(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);//  w w  w. j  a  v a 2 s. c o m

    StringBuilder sb = new StringBuilder();
    sb.append(calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.US)).append(", ")
            .append(calendar.get(Calendar.YEAR));

    return sb.toString();
}

From source file:Main.java

/**
 * Returns the month and release date of the movie
 *
 * @param releaseDate release date in yyyy-MM-dd format
 * @return month and year/*ww w . j  a v  a  2s .  c  o m*/
 */
@NonNull
public static String getDisplayReleaseDate(String releaseDate) {
    if (TextUtils.isEmpty(releaseDate)) {
        return "";
    }
    try {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(DATE_FORMAT.parse(releaseDate));
        return calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.ENGLISH) + " "
                + calendar.get(Calendar.YEAR);
    } catch (ParseException e) {
        return "";
    }
}

From source file:JapaneseCalendar.java

public void paintComponent(Graphics g) {
    int width = 400;
    int height = 400;

    Calendar cal = Calendar.getInstance(locale);
    cal.setTime(new Date());

    String header = cal.getDisplayName(Calendar.MONTH, Calendar.LONG, locale);
    header += " " + cal.get(Calendar.YEAR);

    FontMetrics fm = g.getFontMetrics();
    Insets insets = getInsets();//from w  w w. j  ava  2s .  c o m
    g.setColor(Color.black);
    g.drawString(header, (width - fm.stringWidth(header)) / 2, insets.top + fm.getHeight());

    DateFormatSymbols dfs = new DateFormatSymbols(locale);
    String[] weekdayNames = dfs.getShortWeekdays();
    int fieldWidth = (width - insets.left - insets.right) / 7;
    g.drawString(weekdayNames[Calendar.SUNDAY],
            insets.left + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.SUNDAY])) / 2,
            insets.top + 3 * fm.getHeight());
    g.drawString(weekdayNames[Calendar.MONDAY],
            insets.left + fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.MONDAY])) / 2,
            insets.top + 3 * fm.getHeight());
    g.drawString(weekdayNames[Calendar.TUESDAY],
            insets.left + 2 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.TUESDAY])) / 2,
            insets.top + 3 * fm.getHeight());
    g.drawString(weekdayNames[Calendar.WEDNESDAY],
            insets.left + 3 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.WEDNESDAY])) / 2,
            insets.top + 3 * fm.getHeight());
    g.drawString(weekdayNames[Calendar.THURSDAY],
            insets.left + 4 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.THURSDAY])) / 2,
            insets.top + 3 * fm.getHeight());
    g.drawString(weekdayNames[Calendar.FRIDAY],
            insets.left + 5 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.FRIDAY])) / 2,
            insets.top + 3 * fm.getHeight());
    g.drawString(weekdayNames[Calendar.SATURDAY],
            insets.left + 6 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.SATURDAY])) / 2,
            insets.top + 3 * fm.getHeight());

    int dom = cal.get(Calendar.DAY_OF_MONTH);
    cal.set(Calendar.DAY_OF_MONTH, 1);
    int col = 0;
    switch (cal.get(Calendar.DAY_OF_WEEK)) {
    case Calendar.MONDAY:
        col = 1;
        break;

    case Calendar.TUESDAY:
        col = 2;
        break;

    case Calendar.WEDNESDAY:
        col = 3;
        break;

    case Calendar.THURSDAY:
        col = 4;
        break;

    case Calendar.FRIDAY:
        col = 5;
        break;

    case Calendar.SATURDAY:
        col = 6;
    }
    cal.set(Calendar.DAY_OF_MONTH, dom);

    int row = 5 * fm.getHeight();
    for (int i = 1; i <= cal.getActualMaximum(Calendar.DAY_OF_MONTH); i++) {
        g.drawString("" + i, insets.left + fieldWidth * col + (fieldWidth - fm.stringWidth("" + i)) / 2, row);
        if (++col > 6) {
            col = 0;
            row += fm.getHeight();
        }
    }
}

From source file:arun.com.popularmovies.util.Utility.java

public static String getReleaseDate(String date) {
    if (TextUtils.isEmpty(date))
        return "";
    try {//from   w  w  w .  j  av a  2s . c  o m
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH).parse(date));
        return calendar.get(Calendar.DATE) + " "
                + calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.ENGLISH) + " "
                + calendar.get(Calendar.YEAR);
    } catch (ParseException e) {
        return date;
    }
}

From source file:com.personal.coine.scorpion.jxnuhelper.view.activity.SchoolCalendarActivity.java

@Override
public void onScrollToDate(Calendar calendar) {
    actionBar.setTitle(calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.CHINA));
}

From source file:br.msf.commons.util.AbstractDateUtils.java

/**
 * Returns the day of week name for the given date.
 *
 * @param date   The date to be evaluated.
 * @param locale The desired locale./*  w w  w  .j ava2  s .c  om*/
 * @return The day of week name for the given date.
 */
public static String dayOfWeek(final Object date, final Locale locale) {
    ArgumentUtils.rejectIfNull(date);
    return castToCalendar(date).getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG,
            LocaleUtils.getNullSafeLocale(locale));
}