mmo*_*ris 9 wolfram-mathematica
我有以下字符串:"20110103224832494"它采用以下格式:yyyyMMddHHmmssSSS.yyyy是年份,MM是月份,dd是日,HH是小时,mm是分钟,ss是秒,SSS是毫秒.
我认为以下内容会起作用:
DateList[{"20110103224832494",
{"Year", "Month", "Day", "Hour", "Minute", "Second", "Millisecond"}}
]
Run Code Online (Sandbox Code Playgroud)
但回报:
DateString::str: String 20110103224832494 cannot be interpreted as a date in
format {Year,Month,Day,Hour,Minute,Second,Millisecond}. >>
Run Code Online (Sandbox Code Playgroud)
如果这样有效,它会有效吗?
Bre*_*ion 10
使用:
DateList[{"20110103224832494",
Riffle[{"Year",
"Month",
"Day",
"Hour",
"Minute",
"Second",
"Millisecond"}, ""]}]
Run Code Online (Sandbox Code Playgroud)
你确实指定了"有效",我相信这比DateList以下快两个数量级:
stringDynP[s_String, p_] :=
StringTake[s, Thread@{{0}~Join~Most@# + 1, #} &@Accumulate@p]
toDateList[string_String] :=
MapAt[#/1000` &, #, -1] &[
FromDigits /@ stringDynP[string, {4, 2, 2, 2, 2, 5}]
]
toDateList["20110103224832494"]
Run Code Online (Sandbox Code Playgroud)
{2011, 1, 3, 22, 48, 32.494}
stringDynP是我的"动态分区"功能的字符串改编.
DateList方法产生虚假结果:{2011, 1, 12, 9, 23, 24.094}
Run Code Online (Sandbox Code Playgroud)
据推测,在版本8中,可以使用以下方法:
DateList[
{"20110103224832494",
{"Year", "Month", "Day", "Hour","Minute", "Second", "Millisecond"}},
DateDelimiters -> None
]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
619 次 |
| 最近记录: |