
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
Convert LocalDate to java.util.Date by Timezone Offset
Set the LocalDate to now −
LocalDate date = LocalDate.now();
Now, set the TimeZone offset −
ZoneOffset timeZone = ZoneOffset.UTC;
Convert the LocalDate to java.util.Date −
Date.from(date.atStartOfDay().toInstant(timeZone))
Example
import java.time.LocalDate; import java.time.ZoneOffset; import java.util.Date; public class Demo { public static void main(String[] args) { LocalDate date = LocalDate.now(); System.out.println("Date = "+date); ZoneOffset timeZone = ZoneOffset.UTC; System.out.println(Date.from(date.atStartOfDay().toInstant(timeZone))); } }
Output
Date = 2019-04-19 Fri Apr 19 05:30:00 IST 2019
Advertisements