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

Semrush - keyword research tool

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth
Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

42,849 questions

55,678 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 132 views
2 answers 180 views
1 answer 177 views
1 answer 258 views
1 answer 197 views
...