Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java date time

import java.time.format.DateTimeFormatter;
import java.time.LocalDateTime;  
public class CurrentDateTimeExample1 {  
  public static void main(String[] args) {  
   DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
   LocalDateTime now = LocalDateTime.now();
   System.out.println(dtf.format(now));
  }  
}  
Comment

java time

import java.time.LocalTime; // import the LocalTime class
...
// To display the current time (hour, minute, second, and nanoseconds)
LocalTime time = LocalTime.now();
System.out.println(time); // 11:04:57.416546
Comment

Java Date and Time

import java.time.LocalDate; // import the LocalDate class

public class Main {
  public static void main(String[] args) {
    LocalDate myObj = LocalDate.now(); // Create a date object
    System.out.println(myObj); // Display the current date
  }
}
Comment

Date and time java

public static String findDay(int month, int day, int year) {
       LocalDate ld=LocalDate.of(year,month,day);
       return ld.getDayOfWeek().name();
Comment

time in java

import java.util.Calendar;
import java.util.Date;
import java.time.ZonedDateTime;
public class Example {
   public static void main(String[] args) 
   {
      //Getting the current date
      Date date = new Date();
      //This method returns the time in millis
      long timeMilli = date.getTime();
      System.out.println("Time in milliseconds using Date class: " + timeMilli);

      //creating Calendar instance
      Calendar calendar = Calendar.getInstance();
      //Returns current time in millis
      long timeMilli2 = calendar.getTimeInMillis();
      System.out.println("Time in milliseconds using Calendar: " + timeMilli2);
      
      //Java 8 - toEpochMilli() method of ZonedDateTime
      System.out.println("Getting time in milliseconds in Java 8: " + 
      ZonedDateTime.now().toInstant().toEpochMilli());
   }
}
Comment

PREVIOUS NEXT
Code Example
Java :: system.out.println shortcut 
Java :: how to read a text file in java 
Java :: how to convert int array to integer list in java 
Java :: find if a value is in a 2d array java 
Java :: ++i vs i++ java 
Java :: java 8 group a collections by 2 property 
Java :: java printf double 2 decimal places 
Java :: using buidfeatures to enable viewbinding 
Java :: switch activity android studi 
Java :: install java 8 on windows 10 
Java :: java get random char from alphabet 
Java :: how to add minutes in date in java 
Java :: calendar java add 1 day 
Java :: how to change background tint color programmatically android 
Java :: java get ip address 
Java :: java 2d array for each 
Java :: display an image java 
Java :: setbounds in java 
Java :: sum of 1D array(JAVA) 
Java :: how to divide two ints and get a double java 
Java :: area of circle in java 
Java :: android activity read intent extra 
Java :: what is java plug-in 
Java :: java selenium send keys numbers 
Java :: java jframe actionlistener 
Java :: 2d arraylist in java 
Java :: runnable interface in java 
Java :: AmazonS3ClientBuilder 
Java :: string to hexstring In java 
Java :: Why should we mention a method throws some exception/s? 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =