Answers for "java localdatetime"

3

format localdate java

LocalDate today = LocalDate.now();
 
String formattedDate = today.format(DateTimeFormatter.ofPattern("dd-MMM-yy"));
 
System.out.println(formattedDate);
Posted by: Guest on March-29-2020
0

java instant to localdatetime

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;

// ...

//Convert instant to LocalDateTime, no timezone, add a zero offset / UTC+0
LocalDateTime ldt = LocalDateTime.ofInstant(instant, ZoneOffset.UTC);
Posted by: Guest on January-15-2021
1

java localtime

import java.time.LocalTime;  
public class LocalTimeExample1 {  
  public static void main(String[] args) {  
    LocalTime time = LocalTime.now();  
    System.out.println(time);  
  }  
}
Posted by: Guest on June-20-2021
0

localdatetime java example

LocalDateTime current=LocalDateTime.now();//gets current LocalDateTime
LocalDateTime dateTime=LocalDateTime.of(year,month,day,hour,minute,second);//gets specific LocalDateTime
dateTime.getHour();//get the hour of a DateTime
dateTime.getDayOfWeek();//get number of current day in week
dateTime.isBefore(someOtherDateTime);//checks if it is before another LocalDateTime
dateTime.toLocalDate();//converts it to a LocalDate
dateTime.toLocalTime();//converts it to a LocalTime
Posted by: Guest on April-06-2021
0

java new localdatetime

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Month;

/**
 * Java Program to demonstrate How to use LocalDateTime class in Java 8.
 * LocalDateTime is LocalDate + LocalTime, i.e. date with time

 * @author WINDOWS 8
 */
public class Java8Demo {

    public static void main(String args[])  {

        // LocalDate is date without time in Java 8
        // LocalTime is time without date in Java 8
        // LocalDateTime is both date and time e.g. LocalDate + LocalTime
        // but without Timezone information
        
        
        // LocalDateTime.now() creates a LocalDateTieme object with current
        // date and time
        LocalDateTime rightNow = LocalDateTime.now();
        System.out.println("current datetime : " + rightNow);
        
        
        // LocalDateTime.of() method is a factory method to careate 
        // LocalDateTiem with specific date and time
        LocalDateTime aDateTime = LocalDateTime.of(2015, 
                                           Month.JULY, 29, 19, 30, 40);
        System.out.println("some datetime : " + aDateTime);
        
        // You can also create LocalDateTime object by combining LocalDate
        // and LocalTime
        LocalDate currentDate = LocalDate.now();
        LocalTime currentTime = LocalTime.now();
        LocalDateTime fromDateAndTime = LocalDateTime.of(currentDate,
                                                           currentTime);
        System.out.println("LocalDateTime created by combining LocalDate"
                + " and LocalTime" + fromDateAndTime);
        
        
        // You can also retrieve LocalDate and LocalTime from LocalDateTime
        LocalDate retrievedDate = fromDateAndTime.toLocalDate();
        LocalTime retrievedTime = fromDateAndTime.toLocalTime();
        System.out.println("retreived LocalDate : " + retrievedDate);
        System.out.println("retreived LocalTime : " + retrievedTime);
        
    }

}

Output :
current datetime : 2015-08-02T00:29:53.949
some datetime : 2015-07-29T19:30:40
LocalDateTime created by combining LocalDate 
 and LocalTime2015-08-02T00:29:53.949
retreived LocalDate : 2015-08-02
retreived LocalTime : 00:29:53.949
Posted by: Guest on March-17-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language