Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

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
Comment

how to create localdate object in java

// to get date of today Java 8 class
LocalDate date = LocalDate.now();
Comment

localDate java

package br.com.dicasdejava.fundamentos;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class FormatarLocalDate {

    public static void main(String[] args) {

        //Obtém LocalDate de hoje
        LocalDate hoje = LocalDate.now();

        System.out.println("LocalDate antes de formatar: " + hoje);

        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");

        String hojeFormatado = hoje.format(formatter);

        System.out.println("LocalDate depois de formatar: " + hojeFormatado);

        //Obtém LocalDateTime de agora
        LocalDateTime agora = LocalDateTime.now();

        System.out.println("LocalDateTime antes de formatar: " + agora);

        formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss");

        String agoraFormatado = agora.format(formatter);

        System.out.println("LocalDateTime depois de formatar: " + agoraFormatado);

    }

}
Comment

PREVIOUS NEXT
Code Example
Java :: in java how to throw exception from function 
Java :: java map to list or array 
Java :: int to byte 
Java :: java get year month day hour minute second 
Java :: 12 hours to 24 hours java 
Java :: how to add 2 numbers in java 
Java :: How to count the number of islands (groups of adjacent 1s) in a grid of 1s (land) and 0s (water), in Java? 
Java :: intent flag clear task 
Java :: thread 
Java :: java remove duplicates 
Java :: days between two dates android 
Java :: input array in String in java 
Java :: Java Queue Array Implementation 
Java :: final method meaning 
Java :: convert char to string in java 
Java :: android xml hide 
Java :: java csv line split 
Java :: implement the bubble sort algorithm on the following arraylist 
Java :: Failed to collect dependencies at net.sf.jasperreports:jasperreports:jar:6.2.0 
Java :: uuid from any string java 
Java :: Processing Java examples 
Java :: declare array of chars java 
Java :: fill two dimensional array column by column java 
Java :: java string static arrat 
Java :: how to get current date in java 
Java :: connect sqlite for java 
Java :: javafx textarea size 
Java :: java.lang.string cannot be cast to java.lang.double react native 
Java :: Java push() Method 
Java :: java priority queue 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =