Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,900 questions

51,831 answers

573 users

How to get milliseconds from LocalDateTime in Java

3 Answers

0 votes
import java.time.LocalDateTime;
import java.time.ZoneId;

public class MyClass {
    public static void main(String args[]) {
        LocalDateTime localDateTime = LocalDateTime.now();
        
        long milliseconds = localDateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
        
        System.out.println(milliseconds);    
    }
}
     
     
     
     
/*
run:
     
1699458675114

*/

 



answered Nov 8, 2023 by avibootz
0 votes
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.time.ZoneId;

public class MyClass {
    public static void main(String args[]) {
        LocalDateTime localDateTime = LocalDateTime.now();
  
        ZonedDateTime zdt = ZonedDateTime.of(localDateTime, ZoneId.systemDefault());
        
        long milliseconds = zdt.toInstant().toEpochMilli();
  
        System.out.println(milliseconds);    
    }
}
     
     
     
     
/*
run:
     
1699458892798

*/

 



answered Nov 8, 2023 by avibootz
0 votes
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.time.ZoneId;

public class MyClass {
    public static void main(String args[]) {
        LocalDateTime localDateTime = LocalDateTime.of(2023, 11, 8, 17, 15, 10);
  
        ZonedDateTime zdt = localDateTime.atZone(ZoneId.of("America/Los_Angeles"));
        
        long milliseconds = zdt.toInstant().toEpochMilli();
  
        System.out.println(milliseconds);    
    }
}
     
     
     
     
/*
run:
     
1699492510000

*/

 



answered Nov 8, 2023 by avibootz

Related questions

1 answer 78 views
2 answers 121 views
1 answer 134 views
1 answer 179 views
1 answer 150 views
...