Found 34494 Articles for Programming

Display day number with SimpleDateFormat('d') in Java

Samual Sam
Updated on 30-Jul-2019 22:30:24

162 Views

To display the day number, use the SimpleDateFormat('d') as shown below −Format f = new SimpleDateFormat("d"); String strDay = f.format(new Date()); System.out.println("Day Number = "+strDay);Since, we have used the Format and SimpleDateFormat class above, therefore import the following packages. With that, we have also used the Date −import java.text.Format; import java.text.SimpleDateFormat; import java.util.Date;The following is an example −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { // displaying current date and time Calendar ... Read More

SimpleDateFormat(“HH:mm:ss Z”) in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

2K+ Views

The Z means "zero hour offset", also known as "Zulu time" (UTC) in the ISO 8601 time representation. However, ACP 121 standard defines the list of military time zones and derives the "Zulu time" from theGreenwich Mean Time (GMT).Let us see the usage of SimpleDateFormat(“HH:mm:ss Z”) −Format f = new SimpleDateFormat("HH.mm.ss Z"); String strResult = f.format(new Date()); System.out.println("Time = "+strResult);The following is the complete example that displays time with offset (HH:mm:ss Z) −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { ... Read More

SimpleDateFormat(“HH.mm.ss”) in Java

Samual Sam
Updated on 30-Jul-2019 22:30:24

9K+ Views

The format SimpleDateFormat(“HH.mm.ss”) displays time. To work with SimpleDateFormat class, we have imported the following package.import java.text.SimpleDateFormat;Here, we are using the SimpleDateFormat class to display date and time. Let us set it for the format we want i.e time - HH.mm.ss −Format f = new SimpleDateFormat("HH.mm.ss"); String strResult = f.format(new Date()); System.out.println("Time = "+strResult);The following is an example −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { // displaying current date and time ... Read More

SimpleDateFormat(“hh:mm:ss a”) in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

3K+ Views

The following format displays time from −hh:mm:ssThe following format displays time with AM/ PM marker −hh:mm:ss aHere, we are using the SimpleDateFormat class to display date and time. Let us set it for the format we want i.e time and AM/PM Marker −Format f = new SimpleDateFormat("hh:mm:ss a"); String strResult = f.format(new Date()); System.out.println("Time = "+strResult);The following is an example −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { // displaying current date and time ... Read More

SimpleDateFormat(“Z”) in Java

Samual Sam
Updated on 30-Jul-2019 22:30:24

5K+ Views

The Z means "zero hour offset", also known as "Zulu time" (UTC) in the ISO 8601 time representation. However, ACP 121 standard defines the list of military time zones and derives the "Zulu time" from the Greenwich Mean Time (GMT).TimeZone can be formatted in z, Z or zzzz formats.The following is an example that displays how to implement SimpleDateFormat(“Z”) −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { // displaying current date and time ... Read More

Convert Long into String using toString() method of Long class in java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

137 Views

The toString() method gives string representation to a Long. Let’s say we have the following Long object −Long longObj = new Long(70); System.out.println("Long: " + longObj);To convert it to String, the toString() method is used −String myStr = longObj.toString();The following is the complete example −Example Live Demopublic class Demo { public static void main(String[] args) { // Long Long longObj = new Long(70); System.out.println("Long: " + longObj); // conversion String myStr = longObj.toString(); System.out.println("Converted to String: " + myStr); } }OutputLong: 70 Converted to String: 70

Convert String to Long in Java

Samual Sam
Updated on 30-Jul-2019 22:30:24

310 Views

To convert String to Long, use the valueOf() method.Let’s say the following is our string.// string String myStr = "5"; System.out.println("String: "+myStr);To convert it to Long, we have used valueOf() −Long longObj = Long.valueOf(myStr);The following is the complete example to convert a String value to Long −Example Live Demopublic class Demo { public static void main(String[] args) { // string String myStr = "5"; System.out.println("String: "+myStr); // long Long longObj = Long.valueOf(myStr); System.out.println("Converted to Long: "+longObj); } }OutputString: 5 Converted to Long: 5

Java program to get the minimum of three long values

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

60 Views

Firstly, let us declare and initialize three long values.long val1 = 88799; long val2 = 98567; long val3 = 98768;Now, find the minimum of three long values using the following condition −// checking for maximum if (val2 < val1) { val1 = val2; } if (val3 < val1) { val1 = val3; }The following is the complete example to get the minimum value −Example Live Demopublic class Demo { public static void main(String[] args) { long val1 = 88799; long ... Read More

Java Program to get the maximum of three long values

Samual Sam
Updated on 30-Jul-2019 22:30:24

146 Views

Firstly, let us declare and initialize three long values −long val1 = 98799; long val2 = 98567; long val3 = 98768;Now, find the maximum of three long values using the following condition −// checking for maximum if (val2 > val1) { val1 = val2; } if (val3 > val1) { val1 = val3; }The following is the complete example to get the maximum value −Example Live Demopublic class Demo { public static void main(String[] args) { long val1 = 98799; ... Read More

Formatting Minute in m format in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

237 Views

The “m” format is to format minutes i.e. 1, 2, 3, 4, etc. Here, we will use the following.SimpleDateFormat("m");Let us see an example −// displaying minutes in m format SimpleDateFormat simpleformat = new SimpleDateFormat("m"); String strMinute = simpleformat.format(new Date()); System.out.println("Minutes in m format = "+strMinute);Above, we have used the SimpleDateFormat class, therefore the following package is imported.import java.text.SimpleDateFormat;The following is an example −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { // displaying current date and time ... Read More

Advertisements