date parse android code example

Example 1: android parse date

import java.time.*;
import java.time.format.*;
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String input = "2021-02-05 13:07:35";
LocalDateTime datetime = LocalDateTime.parse(input, formatter);

Example 2: android java parse date time

import java.time.*;
import java.time.format.*;
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
String input = "13:07:35";
LocalTime time = LocalTime.parse(input, formatter);

Example 3: android java parse date time

import java.time.*;
import java.time.format.*;
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String input = "2021-02-05";
LocalDate date = LocalDate.parse(input, formatter);

Tags:

Java Example