Android - Getting wrong TimeZone abbreviations? Understanding CET vs CEST

81 Views Asked by At

I would like to print the correct TimeZone abbreviation of a Date in Android but I'm a little confused.

As far as I know in the "Europe/Budapest" TimeZone we have "Standard Time" and "Daylight Saving Time" - So the abbreviation for a date during summer in this TimeZone should print CEST (Central European Summer Time) while during winter it should print CET (Central European Time)

So far I made the following function:

  1. I make a timestamp.
  2. I make a Date object from the given timestamp.
  3. I make a Calendar instance.
  4. I set the Calendar's time parameter the previous Date object I created.
  5. I set the Calendar's TimeZone as the following: "Europe/Budapest"

I run this function with a summer and a winter timestamp and the output is:

TIME_ = = = Winter date = = = 
TIME_ ts: 1701687285000
TIME_ date: Mon Dec 04 11:54:45 GMT+01:00 2023
TIME_ calendar's timezone: Central European Standard Time
TIME_ calendar's date: Mon Dec 04 11:54:45 GMT+01:00 2023

TIME_ = = = Summer date = = = 
TIME_ ts: 1688205285000
TIME_ date: Sat Jul 01 11:54:45 GMT+02:00 2023
TIME_ calendar's timezone: Central European Standard Time
TIME_ calendar's date: Sat Jul 01 11:54:45 GMT+02:00 2023

Both of the dates have "Central European Standard Time" but it is wrong isn't it? The winter date should have "Central European Time" since the summer date is CEST while the winter date is CET.


Code of the function:

   fun printDate(label: String, ts: Long ) {
        Log.i("TIME_", "= = = " + label + " = = = ")
        val date = Date(ts)
        Log.i("TIME_", "ts: " + ts)
        Log.i("TIME_", "date: " + date)
        val cal = Calendar.getInstance()
        cal.time = date
        cal.timeZone = TimeZone.getTimeZone("Europe/Budapest")
        Log.i("TIME_", "calendar's timezone: " + cal.timeZone.getDisplayName(Locale.ENGLISH))
        Log.i("TIME_", "calendar's date: " + cal.time)
    }

What am I miscalculating here?

Thanks in advance.

0

There are 0 best solutions below