>>> import time
>>> t=1440935442
>>> time.strftime("%Y/%m/%d-%H:%M:%S %z",time.gmtime(t))
'2015/08/30-11:50:42 +0000'
>>> time.strftime("%Y/%m/%d-%H:%M:%S %z",time.localtime(t))
'2015/08/30-13:50:42 +0000'
Run Code Online (Sandbox Code Playgroud)
偏移量保持不变 +0000,但我预计 '2015/08/30-13:50:42 +0200'
时区正确,因为该命令按其应有的方式解释大写 %Z
>>> time.strftime("%Y/%m/%d-%H:%M:%S %Z",time.localtime(t))
'2015/08/30-13:50:42 CEST'
Run Code Online (Sandbox Code Playgroud)
Unix 日期像我想要的那样工作
$ date -u --date @1440935442 +"%Y/%m/%d-%H:%M:%S %z"
2015/08/30-11:50:42 +0000
$ date --date @1440935442 +"%Y/%m/%d-%H:%M:%S %z"
2015/08/30-13:50:42 +0200
Run Code Online (Sandbox Code Playgroud) 因为我完全迷失在你在 stackoverflow 上找到的几十种时间戳转换方法,所以我会在这里问完整的问题:
从 apache 日志(在 CEST 时区)转换此时间戳:
30/Aug/2015:05:13:53 +0200
Run Code Online (Sandbox Code Playgroud)
进入这个:
1440904433
Run Code Online (Sandbox Code Playgroud)
使用
$ python --version
Python 2.6.6
Run Code Online (Sandbox Code Playgroud)
确认:
$ date --date @1440904433
Sun Aug 30 05:13:53 CEST 2015
$ date -u --date @1440904433
Sun Aug 30 03:13:53 UTC 2015
Run Code Online (Sandbox Code Playgroud)
不好的结果是:
1440911633
1440908033
Run Code Online (Sandbox Code Playgroud)
我当前的代码到这里为止:
>>> from dateutil import parser
>>> parser.parse("30/Aug/2015:05:13:53 +0200".replace(':',' ',1))
datetime.datetime(2015, 8, 30, 5, 13, 53, tzinfo=tzoffset(None, 7200))
Run Code Online (Sandbox Code Playgroud)
请不要提出 pytz 模块,我没有它,我无法安装它。请不要为python3提出解决方案
我想使用配置来设置sshCommand而不是环境变量。但不起作用这是发生了什么
? GIT_SSH_COMMAND='ssh -i /var/www/level2.lu/www/git_id_rsa -F /dev/null' git ls-remote
From git@github.com:syn2cat/Level2.lu.git
fcaa5a2e63499568dd916e7b18f950b311781bd0 HEAD
fcaa5a2e63499568dd916e7b18f950b311781bd0 refs/heads/master
a542061a64d3698d5da54d63456b26932fe549a2 refs/pull/1/head
? git config core.sshcommand
ssh -i /var/www/level2.lu/www/git_id_rsa -F /dev/null
? git ls-remote
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Run Code Online (Sandbox Code Playgroud)
并进行调试,它不使用core.sshCommand中的值
? GIT_TRACE=1 git ls-remote
13:46:15.366401 git.c:344 trace: built-in: git 'ls-remote'
13:46:15.366564 run-command.c:334 trace: run_command: 'ssh' 'git@github.com' 'git-upload-pack '\''syn2cat/Level2.lu.git'\'''
Run Code Online (Sandbox Code Playgroud)
版本号
? lsb_release -a
No LSB modules are available. …Run Code Online (Sandbox Code Playgroud)