[英]How to parse a Sharepoint Date from Hex to a java.util.Date
I'm trying to parse a Date from a MS Sharepoint into a java.util.Date. 我正在尝试将MS Sharepoint中的Date解析为java.util.Date。 The Details: I query a Sharepoint from a Grails webapp via the SOAP GetListItems method.
详细信息:我通过SOAP GetListItems方法从Grails Web应用程序查询一个Sharepoint。 In the Sharepoint list, the date is displayed correctly, here 09/11/2009 but in the SOAP response, I get
在Sharepoint列表中,正确显示了日期,这里是09/11/2009,但是在SOAP响应中,我得到了
0x01ca60cf|0x94894000Further, this only happens with docx, pptx, etc. file types.
After a bit of educated trial and error, I ended up with this: 经过一些有教养的反复试验后,我得出以下结论:
def date = "0x01ca60cf|0x94894000"
// Parse our hex numbers into a single number
def nums = Long.parseLong( date.split( /\|/ ).collect { it.replace( '0x', '' ) }.join( '' ), 16 ) / 10000
// MS calendar goes from 1600... Java's goes from 1970, so we need to make up the difference
nums += Calendar.instance.updated( year:1601, month:0, date:1 ).time.time
println "Converted date is ${new Date( nums as Long )}"
You would probably want to do much more testing to make sure it isn't just a fluke I get the right date on this occasion... 您可能需要做更多的测试,以确保这不是偶然,我在这种情况下得到了正确的约会...
Do you have more values to test it on? 您是否有更多价值可以对其进行测试?
EDIT ... 编辑 ...
Ahhh...the only bit I wasn't sure about was why I needed to do / 10000
, but the documentation for ticks in the DateTime object shows that: 啊...我不确定的唯一原因是为什么我需要这样做
/ 10000
,但是DateTime对象中滴答声的文档显示:
A single tick represents one hundred nanoseconds or one ten-millionth of a second.
一个滴答声代表一百纳秒或一百万分之一秒。 There are 10,000 ticks in a millisecond.
毫秒内有10,000个滴答声。
Which explains it :-) 解释它:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.