Answers for "change the timezone of java.util.Date"

1

get date by timezone java

Date date = new Date();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

// Use Madrid's time zone to format the date in
df.setTimeZone(TimeZone.getTimeZone("Europe/Madrid"));

System.out.println("Date and time in Madrid: " + df.format(date));
Posted by: Guest on July-23-2020
0

java java.util.TimeZone to java.time.ZoneId

package com.javabrahman.java8.time;
import java.time.ZoneId;
import java.util.TimeZone;
public class TimeZoneToZoneId {
  public static void main(String args[]) {
 
    //Converting system's 'default' java.util.TimeZone to java.time.ZoneId
    ZoneId zoneId = TimeZone.getDefault().toZoneId();
    System.out.println("ZoneId from default system TimeZone: " + zoneId);
 
    //Converting custom defined java.util.TimeZone to java.time.ZoneId
    TimeZone timeZoneLA = TimeZone.getTimeZone("America/Los_Angeles");
    ZoneId zoneIdLA = timeZoneLA.toZoneId();
    System.out.println("ZoneId from custom 'LA' TimeZone: " + zoneIdLA);
 
  }
}
Posted by: Guest on May-19-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language