Click here to watch on Youtube:
https://www.youtube.com/watch?v=PN6pE3WbkSE&list=UUhwKlOVR041tngjerWxVccw
CalendarDemo.java
Output
Click the below link to download the code:
https://sites.google.com/site/ramj2eev2/java_basics/CalendarDemo_getDisplayName.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava_2018/CalendarDemo_getDisplayName
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/259a72fc482a7b514359596bbc1084e51fbbf105/BasicJava_2018/CalendarDemo_getDisplayName/?at=master
See also:
All JavaEE Videos Playlist
All JavaEE Videos
All JAVA EE Links
Spring Tutorial
Servlets Tutorial
All Design Patterns Links
JDBC Tutorial
Java Collection Framework Tutorial
JAVA Tutorial
Kids Tutorial
Cooking Tutorial
https://www.youtube.com/watch?v=PN6pE3WbkSE&list=UUhwKlOVR041tngjerWxVccw
CalendarDemo.java
import java.util.Calendar;
import java.util.Locale;
/**
* public String getDisplayName(int field, int style, Locale locale)
*
* Returns the string representation of the calendar field value in
* the given style and locale.
*
* Parameters:
*
* field - the calendar field for which the string representation is
* returned
*
* style - the style applied to the string representation; one of
* SHORT_FORMAT (SHORT), SHORT_STANDALONE, LONG_FORMAT (LONG),
* LONG_STANDALONE, NARROW_FORMAT, or NARROW_STANDALONE.
*
* locale - the locale for the string representation (any calendar
* types specified by locale are ignored)
*
* Returns:
*
* the string representation of the given field in the given style, or
* null if no string representation is applicable.
*/
public class CalendarDemo
{
public static void main(String[] args)
{
Calendar cal = Calendar.getInstance();
Locale locale = Locale.getDefault();
System.out.println("locale = " + locale);
String displayName = cal.getDisplayName(Calendar.DAY_OF_WEEK,
Calendar.LONG, locale);
System.out.println("Long format = " + displayName);
displayName = cal.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT,
locale);
System.out.println("Short format = " + displayName);
}
}
import java.util.Locale;
/**
* public String getDisplayName(int field, int style, Locale locale)
*
* Returns the string representation of the calendar field value in
* the given style and locale.
*
* Parameters:
*
* field - the calendar field for which the string representation is
* returned
*
* style - the style applied to the string representation; one of
* SHORT_FORMAT (SHORT), SHORT_STANDALONE, LONG_FORMAT (LONG),
* LONG_STANDALONE, NARROW_FORMAT, or NARROW_STANDALONE.
*
* locale - the locale for the string representation (any calendar
* types specified by locale are ignored)
*
* Returns:
*
* the string representation of the given field in the given style, or
* null if no string representation is applicable.
*/
public class CalendarDemo
{
public static void main(String[] args)
{
Calendar cal = Calendar.getInstance();
Locale locale = Locale.getDefault();
System.out.println("locale = " + locale);
String displayName = cal.getDisplayName(Calendar.DAY_OF_WEEK,
Calendar.LONG, locale);
System.out.println("Long format = " + displayName);
displayName = cal.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT,
locale);
System.out.println("Short format = " + displayName);
}
}
Output
locale = en_US
Long format = Friday
Short format = Fri
Long format = Friday
Short format = Fri
Click the below link to download the code:
https://sites.google.com/site/ramj2eev2/java_basics/CalendarDemo_getDisplayName.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava_2018/CalendarDemo_getDisplayName
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/259a72fc482a7b514359596bbc1084e51fbbf105/BasicJava_2018/CalendarDemo_getDisplayName/?at=master
See also:
No comments:
Post a Comment