A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Java program to parse individual components of date from a string
Q:

Java program to parse individual components of date from a string

0

Java program to parse individual components of date from a string

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to parse individual components of date from a string is given below. The given program is compiled and executed successfully.

// Java program to parse individual components 
// of date from a string

import java.util.Date;
import java.time.Month;
import java.time.LocalDate;

class Main {
  public static void main(String args[]) {
    String date = "2022-03-31";

    LocalDate lDate = LocalDate.parse(date);

    int dd = lDate.getDayOfMonth();

    Month mon = lDate.getMonth();

    int yyyy = lDate.getYear();

    System.out.println("Day  : " + dd);
    System.out.println("Month: " + mon);
    System.out.println("Year : " + yyyy);

  }
}

Output:

Day  : 31
Month: MARCH
Year : 2022

Explanation:

In the above program, we created a class Main that contains a static method main(). The main() method is the entry point for the program, here we created a string variable that contains a date in a format. Then we parsed the components of date using methods of LocalDate class and printed the result.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now