Android: time.Local does not reflect the device timezone
Wails version family
v3
Exact Wails version
v3.0.0-beta.26
Operating System
Android (experimental)
Description
On Android, time.Local appears to remain incorrect in some Wails applications, even when the device timezone is configured properly.
I recently encountered this while testing a Wails v3 Android application. Dates and times were behaving as if the application was running in UTC rather than the device's configured timezone (for example Asia/Shanghai).
As a workaround, I manually read Android's timezone property and override time.Local during startup:
//go:build android
package main
/*
#include <sys/system_properties.h>
#include <stdlib.h>
*/
import "C"
import (
"time"
"unsafe"
)
func initAndroidTimeZone() {
cname := C.CString("persist.sys.timezone")
defer C.free(unsafe.Pointer(cname))
var buf [128]C.char
n := C.__system_property_get(cname, &buf[0])
if n <= 0 {
return
}
tz := C.GoStringN(&buf[0], C.int(n))
loc, err := time.LoadLocation(tz)
if err != nil {
return
}
time.Local = loc
}After applying this workaround, time handling became consistent with the Android system timezone.
This feels like something that should ideally be handled by the runtime rather than requiring every application to implement its own Android-specific fix.
One possible improvement would be to expose the device timezone through the existing mobile bridge, similar to how APIs such as application.Mobile.SafeAreaJSON() are currently exposed.
For example:
application.Mobile.Timezone()which could internally use:
TimeZone.getDefault().getID()and return values such as:
Asia/Shanghai
Europe/London
America/New_YorkThis would allow applications to correctly initialize time.Local without relying on Android system properties or custom CGO code.
I'm not sure whether this is a Wails runtime issue, a Go mobile/runtime behavior issue, or expected Android behavior, but I wanted to share the workaround and start a discussion. If this is a known limitation, perhaps exposing timezone information through the mobile bridge would be a useful addition.
To Reproduce
Create a new Wails v3 application targeting Android.
Log the following values during startup:
fmt.Println(time.Now())
fmt.Println(time.Now().Location())
fmt.Println(time.Local)Build and run the application on an Android device configured with a non-UTC timezone (for example, Asia/Shanghai).
Observe that Go's local timezone may not match the device timezone.
Apply the workaround shown in this issue and observe that time handling becomes consistent with the Android system timezone.
Expected behaviour
The application's local timezone should automatically match the Android device timezone.
For example, if the device timezone is set to Asia/Shanghai, then:
time.Now().Location()
### Screenshots
_No response_
### Attempted Fixes
_No response_
### System Details
```shell
Wails v3.0.0-beta.26 › Wails Doctor
# System
┌──────────────────────────────────────────────────────────────────────┐
| Name | Windows 10 Pro |
| Version | 2009 (Build: 26200) |
| ID | 25H2 |
| Branding | Windows 11 专业版 |
| Platform | windows |
| Architecture | amd64 |
| Go WebView2Loader | true |
| WebView2 Version | 153.0.4234.48 |
| CPU | 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz |
| GPU | Intel(R) Iris(R) Xe Graphics (Intel Corporation) |
| Memory | 16GB |
└──────────────────────────────────────────────────────────────────────┘
# Build Environment
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
| Wails CLI | v3.0.0-beta.26 |
| Go Version | go1.27.1 |
| -buildmode | exe |
| -compiler | gc |
| CGO_ENABLED | 0 |
| DefaultGODEBUG | cryptocustomrand=1,tlssecpmlkem=0,tracebacklabels=0,urlstrictcolons=0,x509sslcertoverrideplatform=0 |
| GOAMD64 | v1 |
| GOARCH | amd64 |
| GOOS | windows |
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘Additional context
Verified that the Android device timezone was correctly configured.
Tested Go's standard timezone handling (
time.Local,time.Now().Location()) and found that the reported timezone did not match the device timezone.Searched for existing Wails Android timezone-related issues but could not find a documented solution.
Implemented a workaround by reading Android's
persist.sys.timezonesystem property via CGO and explicitly settingtime.Local, which resolved the issue in my application.
loc, err := time.LoadLocation(tz)
if err == nil {
time.Local = loc
}- Investigated exposing timezone information through the Android bridge (similar to
application.Mobile.SafeAreaJSON()), but this currently does not appear to be available as a built-in mobile API.
Source: wailsapp/wails