convert date to calendar java
public static Calendar toCalendar(Date date){
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return cal;
}
convert date to calendar java
public static Calendar toCalendar(Date date){
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return cal;
}
java 8 string to localdate
package com.mkyong.date;
import java.time.LocalDate;
public class JavaDateExample1 {
public static void main(String[] args) {
String date = "2016-08-16";
//default, ISO_LOCAL_DATE
LocalDate localDate = LocalDate.parse(date);
System.out.println(localDate);
}
}
Copy
localdate to date java
// Localdate to Date
Date.from(localdate.atStartOfDay(ZoneId.systemDefault()).toInstant())
string to localdate in java
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d/MM/yyyy");
String date = "16/08/2016";
//convert String to LocalDate
LocalDate localDate = LocalDate.parse(date, formatter);
date to localdate
dateToConvert.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDate();
how to turna date into a LocalDateTime java
public LocalDateTime convertToLocalDateTimeViaInstant(Date dateToConvert) {
return dateToConvert.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDateTime();
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us