Found 9150 Articles for Object Oriented Programming

Display time zone with SimpleDateFormat(“z”) in Java

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

2K+ Views

You can display timezone easily in Java using SimpleDateFormat(“z”).Firstly, to work with SimpleDateFormat class in Java, import the following package −import java.text.SimpleDateFormat;Now, set the format with SimpleDateFormat(“z”) to display timezone −Format f = new SimpleDateFormat(”z”);Now, get the timezone in a string −String strTimeZone = f.format(new 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 cal = Calendar.getInstance(); ... Read More

Display AM/PM time marker with SimpleDateFormat(“a”) in Java

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

913 Views

You can display AM/PM time marker easily in Java using SimpleDateFormat(“a”).Firstly, to work with SimpleDateFormat class in Java, import the following package.import java.text.SimpleDateFormat;Now, set the format with SimpleDateFormat(“a”) to display AM/PM marker −Format f = new SimpleDateFormat(”a”);Now, get the marker in a string −String strMarker = f.format(new 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 cal = Calendar.getInstance(); ... Read More

Display seconds with SimpleDateFormat('ss') in Java

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

1K+ Views

To work with SimpleDateFormat class in Java, import the following package.import java.text.SimpleDateFormat;Now, set the format with SimpleDateFormat(“ss”) to display seconds in two-digit.Format f = new SimpleDateFormat(”ss”);Now, get the seconds in a string −String strSeconds = f.format(new 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 cal = Calendar.getInstance(); SimpleDateFormat simpleformat = new SimpleDateFormat("dd/MMMM/yyyy hh:mm:s"); ... Read More

Display seconds with SimpleDateFormat(“s”) in Java

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

285 Views

To work with SimpleDateFormat class in Java, import the following package.import java.text.SimpleDateFormat;Now, set the format with SimpleDateFormat(“s”) to display seconds in one-digit.Format f = new SimpleDateFormat(”s”);Now, get the seconds in a string.String strSeconds = f.format(new 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 cal = Calendar.getInstance(); SimpleDateFormat simpleformat = new SimpleDateFormat("dd/MMMM/yyyy hh:mm:s"); ... Read More

Display hour with SimpleDateFormat(“hh”) in Java

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

289 Views

To work with SimpleDateFormat class in Java, import the following package.import java.text.SimpleDateFormat;Now, set the format with SimpleDateFormat(“hh”) to display hour −Format f = new SimpleDateFormat("hh");Now, get the hour in a string −String strHour = f.format(new 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 { Calendar cal = Calendar.getInstance(); SimpleDateFormat simpleformat = new SimpleDateFormat("dd/MMMM/yyyy hh:mm:s"); System.out.println("Today's date = "+simpleformat.format(cal.getTime())); ... Read More

Display today’s date in Java with SimpleDateFormat

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

267 Views

To work with SimpleDateFormat class in Java, import the following package.import java.text.SimpleDateFormat;To get the date, use the format() method as shown below. Firstly, set the date format −Calendar cal = Calendar.getInstance(); SimpleDateFormat simpleformat = new SimpleDateFormat("dd/MM/yyyy");Now, we will get the date −simpleformat.format(cal.getTime())The following is the complete example −Example Live Demoimport java.text.SimpleDateFormat; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { Calendar cal = Calendar.getInstance(); SimpleDateFormat simpleformat = new SimpleDateFormat("dd/MM/yyyy"); System.out.println("Today's date = "+simpleformat.format(cal.getTime())); ... Read More

Java program to display date and time information in uppercase

Alshifa Hasnain
Updated on 03-Mar-2025 18:48:48

561 Views

In this article, we will learn to display the date and time in uppercase using Java. Working with date and time in Java is a common requirement in various applications, logging, scheduling, or data processing. Different Approaches The following are the two different approaches to display the date and time in uppercase using Java − Using Formatter and Calendar Using DateTimeFormatter Using Formatter and Calendar The Formatter class in Java allows us to format date and time using the %Tc specifier. We can then convert the output to uppercase using ... Read More

Java Program to display date and time information in lowercase

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

157 Views

Firstly, create a Formatter and a Calendar object.Formatter f = new Formatter(); Calendar c = Calendar.getInstance();To display complete date and time information use the ‘c’ conversion character. However, to display it in lowercase, use ‘tc’ −f = new Formatter(); System.out.println(f.format("Date and Time (lowercase): %tc", cal));The following is an example −Example Live Demoimport java.util.Calendar; import java.util.Formatter; public class Demo { public static void main(String args[]) { Formatter f = new Formatter(); Calendar cal = Calendar.getInstance(); System.out.println("Current date and time: "+cal.getTime()); ... Read More

Java program to display hour and minute in AM or PM

Samual Sam
Updated on 07-Nov-2024 01:06:05

516 Views

In this article, we will learn how to format date and time in Java using the Formatter and Calendar classes. The Formatter class allows for flexible string formatting, and the Calendar class is useful for retrieving and manipulating date and time values. We will use these classes to display the current hour, minute, and AM/PM marker. Problem StatementGiven a Calendar instance, write a Java program to display the current hour, minute, and AM/PM marker using the Formatter class.Input The program fetches the current date and time using the Calendar class.Output Current date and time: Mon Nov 26 07:41:35 UTC 2018 ... Read More

Display just hour and minute using Formatter in Java

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

262 Views

Firstly, create a Formatter and a Calendar object.Formatter f = new Formatter(); Calendar c = Calendar.getInstance();To display hour using Formatter class, use the ‘l’ conversion a character −f = new Formatter(); System.out.println(f.format("Hour: %tl", c));To display minute using Formatter class, use the ‘M’ conversion character −f = new Formatter(); System.out.println(f.format("Minute: %1$tM", c));The following is an example −Example Live Demoimport java.util.Calendar; import java.util.Formatter; public class Demo { public static void main(String args[]) { Formatter f = new Formatter(); Calendar c = Calendar.getInstance(); ... Read More

Advertisements