Samual Sam has Published 2310 Articles

Java Program to set date formats for different countries

Samual Sam

Samual Sam

Updated on 27-Jun-2020 13:21:27

450 Views

Firstly, set the locale −Locale[] strLocales = { US, UK, GERMANY};Now, let us set the date formats i.e. different constants −int[] constants = { SHORT, MEDIUM, LONG }; String[] str = { "SHORT", "MEDIUM", "LONG" };Loop through and get the different date formats for different countries −for (Locale country : ... Read More

Java Program to format time using Custom Format

Samual Sam

Samual Sam

Updated on 27-Jun-2020 13:20:01

222 Views

Firstly, set the time with SimpleDateFormat classFormat dateFormat = new SimpleDateFormat("h:m:s");Now, for custom format, let us fetch the hour, minute and second individuallyHour// hour dateFormat = new SimpleDateFormat("h"); String strHour = dateFormat.format(new Date()); System.out.println("Hour: "+strHour);Minute// minute dateFormat = new SimpleDateFormat("m"); String strMinute = dateFormat.format(new Date()); System.out.println("Minute: "+strMinute);Second// second dateFormat = ... Read More

Java Program to format date with SimpleDateFormat

Samual Sam

Samual Sam

Updated on 27-Jun-2020 13:02:02

278 Views

The SimpleDateFormat class is used to parse and format dates. To create an object, firstly import the following packageimport java.text.SimpleDateFormat;Set the dateString strDate = "'Year = '"; strDate += "yyyy"; strDate += "'Month = '"; strDate += "MMMMMMMMM"; strDate += "'Hours = '"; strDate += "hh"; strDate += "a"; strDate ... Read More

Java Program to format date with DateFormat.FULL

Samual Sam

Samual Sam

Updated on 27-Jun-2020 12:59:07

368 Views

DateFormat.FULL is a constant for full style pattern.Firstly, we will create Date object −Date dt = new Date(); DateFormat dateFormat;Let us format date for different locale with DateFormat.FULL −// FRENCH dateFormat = DateFormat.getDateInstance(DateFormat.FULL, Locale.FRENCH); // CANADA dateFormat = DateFormat.getDateInstance(DateFormat. FULL, Locale.CANADA);The following is an example −Example Live Demoimport java.text.DateFormat; import java.util.Date; ... Read More

Java Program to format time with DateFormat.MEDIUM

Samual Sam

Samual Sam

Updated on 27-Jun-2020 12:58:00

265 Views

Use the getTimeInstance() method in Java to get the time format for the locale you have set. DateFormat.MEDIUM is a constant for medium style pattern.Firstly, we will create a Date object −Date dt = new Date(); DateFormat dateFormat;Let us format time for a different locale with DateFormat.MEDIUMdateFormat = DateFormat.getTimeInstance(DateFormat.MEDIUM, Locale.CANADA); ... Read More

Format time with DateFormat.FULL in Java

Samual Sam

Samual Sam

Updated on 27-Jun-2020 12:54:58

500 Views

Use the getTimeInstance() method in Java to get the time format for the locale you have set. DateFormat.FULL is a constant for full style pattern.Firstly, we will create Date objectDate dt = new Date(); DateFormat dateFormat;Let us format time for different locale with DateFormat.FULLdateFormat = DateFormat.getTimeInstance(DateFormat.FULL, Locale.CHINESE); System.out.println("Locale CHINESE = ... Read More

Java Program to parse date and time

Samual Sam

Samual Sam

Updated on 27-Jun-2020 12:47:00

264 Views

Create a SimpleDateFormat object −SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss");Do not forget to import the following package for SimpleDateFormat class −import java.text.SimpleDateFormat;Now, since we have set the format for date above, let us parse the date using parseObject() method −Date dt = (Date) dateFormat.parseObject("2018.11.22.11.50.15");The following is an example −Example Live Demoimport java.util.Date; ... Read More

Java Program to parse string date value with default format

Samual Sam

Samual Sam

Updated on 27-Jun-2020 12:43:56

135 Views

For default format, use −DateFormat.getDateInstance(DateFormat.DEFAULT)To parse the string date value, use the parse() methodDate dt = DateFormat.getDateInstance(DateFormat.DEFAULT).parse("Nov 19, 2018");The following is an example −Example Live Demoimport java.text.DateFormat; import java.util.Date; public class Demo {    public static void main(String[] argv) throws Exception {       // parse date       ... Read More

Display Date in E MMM dd yyyy format in Java

Samual Sam

Samual Sam

Updated on 27-Jun-2020 12:42:43

3K+ Views

Firstly, import the following Java packages −import java.text.SimpleDateFormat; import java.util.Date;Now, create objects −Date dt = new Date(); SimpleDateFormat dateFormat;Displaying date in the format we wantdateFormat = new SimpleDateFormat("E MMM dd yyyy");The following is an example −Example Live Demoimport java.text.SimpleDateFormat; import java.util.Date; public class Demo {    public static void main(String args[]) ... Read More

CSS play-during property

Samual Sam

Samual Sam

Updated on 27-Jun-2020 12:25:48

88 Views

This property specifies a sound to be played as a background while an element's content is spoken. Possible values could be any of the followings −URI − The sound designated by this is played as a background while the element's content is spoken.mix − When present, this keyword means ... Read More

Advertisements