Maruthi Krishna has Published 1023 Articles

What are SimpleDateFormat Format Codes in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 06-Feb-2021 03:55:45

149 Views

The java.text.SimpleDateFormat class is used to format and parse a string to date and date to string.Parsing a date stringOne of the constructors of this class accepts a String value representing the desired date format and creates SimpleDateFormat object. To parse/convert a string as a Date objectInstantiate this class by passing ... Read More

How to format year using SimpleDateFormat in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 06-Feb-2021 03:55:23

98 Views

The java.text.SimpleDateFormat class is used to format and parse a string to date and date to string. To parse a date string −Instantiate this class by passing desired format string.Parse the date string using the parse() method.ExampleLive Demoimport java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Sample {    public static void ... Read More

What are various ways to compare dates in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 06-Feb-2021 03:49:47

268 Views

Using the LocalDate classThe java.time.LocalDate class represents the local date i.e. the date without time zone, you can use this object instead of Date. This class provides various methods such as isBefore(), isAfter() and, isEqual() to compare two dates −ExampleLive Demoimport java.time.LocalDate; public class Sample {    public static void main(String ... Read More

How to compare two dates in String format in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 06-Feb-2021 03:49:19

5K+ Views

The java.text.SimpleDateFormat class is used to format and parse a string to date and date to string.One of the constructors of this class accepts a String value representing the desired date format and creates SimpleDateFormat object. To parse/convert a string as a Date object Instantiate this class by passing desired format string.Parse ... Read More

What are various ways to compare time values in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 06-Feb-2021 03:48:47

738 Views

The LocalTime class represents the local time i.e. the time without time zone. This class provides various methods such as isBefore(), isAfter() and, isEqual() to compare two times.ExampleLive Demoimport java.time.LocalTime; public class Test {    public static void main(String args[]) {         LocalTime Time1 = LocalTime.of(10, 15, ... Read More

How to compare two dates along with time in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 06-Feb-2021 03:47:06

543 Views

The java.time.LocalDateTime class represents the local date and time i.e. the date without time zone, you can use this object instead of Date. This class provides various methods such as isBefore(), isAfter() and, isEqual() to compare two dates −ExampleLive Demoimport java.time.LocalDateTime; public class Test {    public static void main(String args[]) ... Read More

How to Format a Date String using SimpleDateFormat in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 06-Feb-2021 03:45:39

155 Views

One of the constructors of this class accepts a String value representing the desired date format and creates SimpleDateFormat class. To parse/convert a string as a Date object −Instantiate this class by passing desired format string.Parse the date string using the parse() method.ExampleLive Demoimport java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Sample ... Read More

How to create Date object from String value in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 06-Feb-2021 03:45:19

1K+ Views

Using the SimpleDateFormat classOne of the constructors of this class accepts a String value representing the desired date format and creates SimpleDateFormat class. To parse/convert a string as a Date object −Instantiate this class by passing desired format string.Parse the date string using the parse() method.ExampleLive Demoimport java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; ... Read More

How to get a Date from year, month and day in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 05-Feb-2021 10:47:28

4K+ Views

Using the of() methodThe of() method of the java.time.LocalDate class accepts the values of the year, month, and day of month as parameters, creates and returns an object of the LocalDate.ExampleLive Demoimport java.time.LocalDate; public class Test {    public static void main(String[] args) {       LocalDate date = LocalDate.of(2014, 9, 11);   ... Read More

How to get the current date and time in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 05-Feb-2021 10:46:57

2K+ Views

You can get the current date and time in Java in various ways. Following are some of them −The constructor of Date classThe no-arg constructor of the java.util.Date class returns the Date object representing the current date and time.ExampleLive Demoimport java.util.Date; public class CreateDate {    public static void main(String args[]) ... Read More

Previous 1 ... 5 6 7 8 9 ... 103 Next
Advertisements