【问题标题】:Android terminal command to get the current dateAndroid终端命令获取当前日期
【发布时间】:2013-10-03 15:29:08
【问题描述】:

我在MK808安卓棒上开发,我需要设置时区和日期。

用于设置我使用的时区 -> su -c setprop persist.sys.timezone "America/Chicago"

这个命令工作正常,但它不会在那个时候改变设备时钟本身我需要重新启动我的设备。设备重新启动后,设备时间按预期更改为 CST。

我尝试执行命令“date”来获取当前日期。我的问题是我从该命令获得的日期应该偏移到夏令时还是不需要偏移?

有人可以告诉我在更改时区后消除设备重启的解决方案吗?因此,一旦我更改时区,我的设备时钟就应该更改。

谢谢!

【问题讨论】:

    标签: android time


    【解决方案1】:

    更改时区不会更改时钟,时钟通常是自 1970 年 1 月 1 日 UTC 以来的秒数。它只是改变了时间的解释方式。

    如果TZ 环境变量在tzset_locked 中为NULL,则查询persist.sys.timezone 属性。如果您希望属性生效,请确保您没有设置TZ

    % adb shell
    # date
    Thu Oct  3 13:33:34 PDT 2013
    # TZ=US/Eastern date                                                
    Thu Oct  3 16:33:38 EDT 2013
    

    快速查看仿生 libc 中的代码表明,每次调用 localtime() 时都会检查 persist.sys.timezone。属性集立即生效:

    # date
    Thu Oct  3 13:39:42 PDT 2013
    # setprop persist.sys.timezone US/Eastern
    # date
    Thu Oct  3 16:39:51 EDT 2013
    

    但是,这只适用于本机代码。 Android 框架有自己的时区处理(例如,您可以看到它在 runtime init 期间检查属性)。

    【讨论】:

      猜你喜欢
      • 2013-08-29
      • 2019-04-11
      • 1970-01-01
      • 2015-11-04
      • 2012-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-26
      相关资源
      最近更新 更多