在UNIX中将Julian时间戳转换为常规时间 [英] Convert Julian Timestamp to Regular Time in UNIX
问题描述
我需要使用Bash在UNIX中将Julian时间戳转换为Regular时间戳.
I need to convert Julian timestamp to Regular timestamp in UNIX using Bash.
在串联操作系统上,转换非常简单-
On Tandem OS, conversion is pretty straightforward -
示例:212186319010244541
Example: 212186319010244541
$OLSAPP SYSTST 1> #interprettimestamp 212186319010244541
#interprettimestamp 212186319010244541 expanded to:
2455860 2011 10 25 16 10 10 244 541
我希望在UNIX环境中也做同样的事情.转换将成为解析器脚本的一部分.因此,单线将不胜感激.
I wish to do the same on UNIX environment. The conversion will be a part of a parser script. So one-liners would be greatly appreciated.
更新:
Tandem上的INTERPRETTIMESTAMP内置函数返回一个由空格分隔的九个数字的列表,包括朱利安天数,年,月,日,小时,分钟,秒,毫秒和微秒.
INTERPRETTIMESTAMP inbuilt function on Tandem returns a space-separated list of nine numbers, consisting of the Julian day number, year, month, day, hour, minute, second, millisecond, and microsecond.
推荐答案
假定数字如@blahdiblah所说
Assuming the number is as @blahdiblah says
代表自公元前4713年1月1日以来的微秒数的值."
"a value representing the number of microseconds since January 1, 4713 B.C."
然后,您首先需要知道1970年1月1日的朱利安时间戳,这是Unix时间的纪元.因此,笨拙的oracle查询会给出
Then you first need to know the Julian timestamp for 01-JAN-1970 which is the epoch for unix time. So a cludgy oracle query gives
210866803200000000
然后您可以从理论上讲仅具有一个shell命令即可计算自1970年1月1日以来的秒数.
Then you could in theory just have a shell command to compute the number of seconds since 1-Jan-1970.
unixtime=$(( ( 212186319010244541 - 210866803200000000 ) / 1000000 ))
与此有关的问题是:
- 您仍然需要对其进行格式化
- 您的bash可能不喜欢带有18位数字的整数算术运算.(请以64位而不是32位为准).
现在,如果您已经安装了perl,则可以使用 bigint
和 POSIX
模块来解决这些问题.作为外壳的一个"内衬,它看起来像
Now if you have perl installed you can solve these using the bigint
and POSIX
modules. As a shell "one" liner it looks like
perl -mbigint -mPOSIX -e 'print( POSIX::strftime("%Y-%m-%d %T",localtime( ($ARGV[0]-210866803200000000)/1000000 ) )."\n")' 212186319010244541
哪个给
2011-10-25 15:10:10
1小时的差异可能是由于夏令时的差异.它可能在perl中,或者更可能是我在1970年1月1日使用的值需要一个小时.因此,您可能需要检查它们两者,以确保其适用于您的系统.
The 1 hour difference is probably due to daylight savings differences. It could be either in the perl, or more likely the value I used for 01-Jan-1970 could be an hour out. So you may need to check both of them to be sure its right for your system.
这篇关于在UNIX中将Julian时间戳转换为常规时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!