android_tz.go 576 B

123456789101112131415161718192021
  1. // Copyright 2014 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // kanged from https://github.com/golang/mobile/blob/c713f31d574bb632a93f169b2cc99c9e753fef0e/app/android.go#L89
  5. package main
  6. // #include <time.h>
  7. import "C"
  8. import "time"
  9. func init() {
  10. var currentT C.time_t
  11. var currentTM C.struct_tm
  12. C.time(&currentT)
  13. C.localtime_r(&currentT, &currentTM)
  14. tzOffset := int(currentTM.tm_gmtoff)
  15. tz := C.GoString(currentTM.tm_zone)
  16. time.Local = time.FixedZone(tz, tzOffset)
  17. }