I'm trying to parse a Date from a MS Sharepoint into a java.util.Date. The Details: I query a Sharepoint from a Grails webapp via the SOAP GetListItems method. In the Sharepoint list, the date is displayed correctly, here 09/11/2009 but in the SOAP response, I get
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:
A single tick represents one hundred nanoseconds or one ten-millionth of a second. There are 10,000 ticks in a millisecond.
Which explains it :-)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.