question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[DatePicker] Incorrect TimeZones

See original GitHub issue

Description:

There seems to be some strange behavior with time zones with the new date picker I am in New Zealand so our time zone is currently UTC+13 and was testing around 9am

As shown below, it is displaying yesterday as today (I increased the valid date range to include yesterday as it is hidden if not in the range)

image

Also when setting the initially selected date via MaterialDatePicker.Builder.datePicker().setSelection(), if the millis for a specific UTC date/time is given, it is not accounting for the time zone offset and is selecting the day prior. Currently our workaround is to manually add the millisecond difference from UTC to local time.

Android API version:

Min 27, Target/compile 29

Material Library version:

1.1.0-rc01

Device:

Zebra TC51

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:17
  • Comments:31 (9 by maintainers)

github_iconTop GitHub Comments

15reactions
Hesamedincommented, Jun 4, 2020

I am using 1.3.0-alpha01 and have the same problem.

So, this is my workaround.

val picker = MaterialDatePicker.Builder.datePicker()
            .....
            .build()
picker.show(supportFragmentManager, picker.toString())
picker.addOnPositiveButtonClickListener {
            val utcTime = Date(it)
            val format = "yyy/MM/dd HH:mm:ss"
            val sdf = SimpleDateFormat(format, Locale.getDefault())
            sdf.timeZone = TimeZone.getTimeZone("UTC")
            val gmtTime = SimpleDateFormat(format, Locale.getDefault()).parse(sdf.format(utcTime))
            gmtTime?.let {  date ->
                vm.setNextDueDate(date.time)
            }
}
5reactions
danielandujarcommented, Feb 16, 2022

Feb 2022, This issue is still happening in 1.5.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Material Date Range Picker showing incorrect current date ...
The date range picker should show the correct date despite of the timezones. One solution for the problem would be to change the...
Read more >
Handling the time zone issue in Material Date Picker ... - Reddit
There seems to be a issue related to time zone in Material Date Picker which shows wrong dates for default selection, current date,...
Read more >
How to make date input / date picker display the date as if it ...
My problem is that if the user that initially creates this birth date lives in the Eastern US time zone, and then a...
Read more >
How to set to false the time-zone | jQuery Forums - Syncfusion
The Timezone API of Datepicker is used to control the conversion of Date values to its equivalent UTC date to avoid differences in...
Read more >
Date Picker Sends Wrong Date - Power Platform Community
Excel's default time zone is UTC. · PowerApps' default time zone is local time zone. · So when PowerApps load time, it will...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found