Karthikeya Boyini has Published 2383 Articles

Java Program to display time in 24-hour format

karthikeya Boyini

karthikeya Boyini

Updated on 27-Jun-2020 13:05:35

3K+ Views

Use the SimpleDateFormat class to display time in 24-hour format.Set the formatDate dt = new Date(); SimpleDateFormat dateFormat; dateFormat = new SimpleDateFormat("kk:mm:ss");Now, the following will display time in 24-hour formatdateFormat.format(dt)The following is an exampleExample Live Demoimport java.text.SimpleDateFormat; import java.util.Date; public class Demo {    public static void main(String[] argv) throws Exception ... Read More

Format date with DateFormat.SHORT in Java

karthikeya Boyini

karthikeya Boyini

Updated on 27-Jun-2020 13:00:29

3K+ Views

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

Format time with DateFormat.SHORT in Java

karthikeya Boyini

karthikeya Boyini

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

384 Views

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

Java Float isInfinite() Method

karthikeya Boyini

karthikeya Boyini

Updated on 27-Jun-2020 12:57:19

89 Views

The Float.isInfinite() method in Java returns true if this Float value is infinitely large in magnitude, else false is returned.We have the following Float valuesFloat f1 = new Float(5.0/0.0); Float f2 = new Float(10.2/0.0); Float f3 = new Float(0.0/0.0);Check with isInfinite() methodf1.isInfinite(); f2.isInfinite(); f3.isInfinite();The following is the complete example with ... Read More

Java Program to format time with DateFormat.LONG

karthikeya Boyini

karthikeya Boyini

Updated on 27-Jun-2020 12:55:38

147 Views

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

Format Date with getDateTimeInstance() in Java

karthikeya Boyini

karthikeya Boyini

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

348 Views

To format date, let us see the DateFormat.SHORT as well as DateFormat.LONG constants. Both of them displays different patterns.Here, we are formatting dates with getDateTimeInstance() method. Use the method to get a date and time format.For DateFormat.SHORT constant −DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); System.out.println(dateFormat.format(calendar.getTime()));For DateFormat.LONG constant −dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG); ... Read More

Parse string date time value input in Java

karthikeya Boyini

karthikeya Boyini

Updated on 27-Jun-2020 12:44:32

316 Views

In Java, you can parse string date time value input usingSimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z");We have used the above class since we imported the following package −import java.text.SimpleDateFormat;Now, we can display the date in the same format −Date dt = (Date) dateFormatter.parseObject("Tue, 20 Nov 2018 16:10:45 -0530");The following is ... Read More

Display Date Time in dd MMM yyyy hh:mm:ss zzz format in Java

karthikeya Boyini

karthikeya Boyini

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

2K+ Views

Firstly, import the following Java packagesimport java.text.SimpleDateFormat; import java.util.Date;Now, create objectsDate dt = new Date(); SimpleDateFormat dateFormat;Displaying date in the format we want −dateFormat = new SimpleDateFormat("dd MMM yyyy hh:mm:ss zzz");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

Set a duration in Java

karthikeya Boyini

karthikeya Boyini

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

123 Views

To set a duration, let us declare two objects of Calendar classCalendar c1 = Calendar.getInstance(); Calendar c2 = Calendar.getInstance();Set a time for one of the calendar objectsc2.add(Calendar.HOUR, 9); c2.add(Calendar.MINUTE, 15); c2.add(Calendar.SECOND, 40);Now, find the difference between both the time. One would be the current time and another we declared above ... Read More

Hinge Animation Effect with CSS

karthikeya Boyini

karthikeya Boyini

Updated on 27-Jun-2020 12:39:12

175 Views

To create hinge animation effect with CSS, you can try to run the following code:ExampleLive Demo                    .animated {             background-image: url(/css/images/logo.png);             background-repeat: no-repeat;             ... Read More

Advertisements