Wolfram mathematica Mathematic8.0是从YYYYMMDDHDHMMSSSS格式的字符串解析日期列表的有效方法

Wolfram mathematica Mathematic8.0是从YYYYMMDDHDHMMSSSS格式的字符串解析日期列表的有效方法,wolfram-mathematica,Wolfram Mathematica,我有以下字符串:“20110103224832494”它的格式如下:yyyymmddhhmmssss。其中yyyy是年,MM是月,dd是日,HH是小时,MM是分钟,ss是秒,SSS是毫秒 我认为以下方法会奏效: DateList[{"20110103224832494", {"Year", "Month", "Day", "Hour", "Minute", "Second", "Millisecond"}} ] 但返回: DateString::str: String 2

我有以下字符串:“20110103224832494”它的格式如下:yyyymmddhhmmssss。其中yyyy是年,MM是月,dd是日,HH是小时,MM是分钟,ss是秒,SSS是毫秒

我认为以下方法会奏效:

DateList[{"20110103224832494",  
         {"Year", "Month", "Day", "Hour", "Minute", "Second", "Millisecond"}}
]
但返回:

DateString::str: String 20110103224832494 cannot be interpreted as a date in 
format {Year,Month,Day,Hour,Minute,Second,Millisecond}. >>
如果这样做有效的话,它会有效率吗?

使用:

DateList[{"20110103224832494",  
   Riffle[{"Year",
           "Month", 
           "Day",   
           "Hour", 
           "Minute", 
           "Second", 
           "Millisecond"}, ""]}]
已更正为将毫秒与秒合并。 您确实指定了“高效”,我相信这比日期列表快两个数量级:

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"]

大概在版本8中,可以使用以下方法:

DateList[
 {"20110103224832494",
   {"Year", "Month", "Day", "Hour","Minute", "Second", "Millisecond"}},
 DateDelimiters -> None
]

我不知道这件事。很好。
日期列表[{“20110103224832494”,“年”,“月”,“日”,“小时”,“分钟”,“秒”,“秒”,“毫秒”}}]
在发布问题后也发现了这一点。为什么它要求在日期/时间规范的其余部分中穿插一个空字符串?@Mr.Wizard,实际上这就是我要问的。更具体地说,我是在问,为什么我需要分离器,而没有分离器?我明白为什么会令人沮丧。mma如何知道在哪里拆分字符串?当然,您的结果实际上不是Mathematica中其他函数可以使用的日期列表。:-)@很明显,
日期列表的行为在版本7和版本8之间发生了变化,因此我感到困惑。请看我更新的答案,我认为这是一个正确且快速的方法。看起来像是第7版中的
日期列表中的错误。当您在规范中添加分钟数时,似乎会感到困惑。。。
{2011, 1, 12, 9, 23, 24.094}
DateList[
 {"20110103224832494",
   {"Year", "Month", "Day", "Hour","Minute", "Second", "Millisecond"}},
 DateDelimiters -> None
]