- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to convert java.util.Date to Instant
First, set the date −
java.util.Date date = new java.util.Date();
Now, convert the above date to Instant −
Instant instant = date.toInstant();
Example
import java.time.Instant; public class Demo { public static void main(String[] args) { java.util.Date date = new java.util.Date(); System.out.println("Date = "+date); Instant instant = date.toInstant(); System.out.println("java.util.Date to Instant = "+instant); } }
Output
Date = Thu Apr 18 23:32:07 IST 2019 java.util.Date to Instant = 2019-04-18T18:02:07.330Z
Advertisements