Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 ZonedDateTime
Create a Date object −
Date date = new Date();
Now, set the ZonedId to default −
final ZoneId id = ZoneId.systemDefault();
Convert java.util.date to ZonedDateTime −
System.out.println(ZonedDateTime.ofInstant(date.toInstant(), id));
Example
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;
public class Demo {
public static void main(String[] args) {
Date date = new Date();
final ZoneId id = ZoneId.systemDefault();
System.out.println(ZonedDateTime.ofInstant(date.toInstant(), id));
}
}
Output
2019-04-19T00:37:33.344+05:30[Asia/Calcutta]
Advertisements