UNIX:以特定格式转换Unix日期

时间:2014-01-15 10:04:07

标签: date unix solaris

我在unix中有一些除当前日期之外的日期,我想转换为特定格式

Original Format
D="Mon Dec 30 06:35:02 EST 2013"

New Format
E=20131230063502

2 个答案:

答案 0 :(得分:1)

E =`日期+%Y%m%d%H%M%S`

这是格式化date命令输出并将其保存在变量E

中的方法

答案 1 :(得分:0)

使用python:

<textarea  style="width:98%;height:150px" onscroll="this.nextSibling.scrollTop=this.scrollTop;">
; This is a comment line
keyword1 keyword2 ; comment
keyword3 "key ; word 4" ; comment

  
"Text; in" and between "quotes; plus" semicolons; this is the comment
  
  ; This is a comment line
  keyword1 keyword2 ; comment
  keyword3 'key ; word 4' ; comment and one quote ' ;see it?
  
_b64decode:
        db    0x83,0xc6,0x3A ; add   si, b64decode_end - _b64decode ;39
        push  'a'   
        pop   di 
  
        cmp   byte [si], 0x2B ; '+'


b64decode_end:
        ;append base64 data here
        ;terminate with printable character less than '+'
        db 'WDVPIVAlQEFQ;WzRcU',"hi;hi",0xfe,"'as;df'" ;'haha"
;"end'
  
</textarea><textarea style="width:98%;height:150px" onscroll="this.previousSibling.scrollTop=this.scrollTop;">
result here
</textarea>
<br><button onclick="demo()">remove comments</button><button onclick="demo_exp()">exp</button>

在:def data(dstr): m = {'Jan': '01', 'Feb':'02', 'Mar':'03', 'Apr':'04', 'May':'05', 'Jun':'06', 'Jul':'07', 'Aug':'08', 'Sep':'09', 'Oct':'10', 'Nov':'11', 'Dec':'12'} val = dstr.split(' ') month = m[val[1]] time = val[3].split(':') return '{}{}{}{}{}{}'.format(val[-1],month,val[2],time[0],time[1],time[2]) if __name__ == '__main__': print data("Mon Dec 30 06:35:02 EST 2013")

出:Mon Dec 30 06:35:02 EST 2013