Last active
          August 29, 2016 20:32 
        
      - 
      
 - 
        
Save CliffordAnderson/f2ad41f7e1ad78c3d7c07dff62553c06 to your computer and use it in GitHub Desktop.  
    Milliseconds since Unix Epoch
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | declare function local:milliseconds-since-epoch($dateTime as xs:dateTime) as xs:integer | |
| { | |
| let $epoch := xs:dateTime("1970-01-01T00:00:00Z") | |
| let $duration := xs:duration($dateTime - $epoch) | |
| let $days := fn:days-from-duration($duration) * 8.64e+7 | |
| let $hours := fn:hours-from-duration($duration) * 3.6e+6 | |
| let $minutes := fn:minutes-from-duration($duration) * 60000 | |
| let $seconds := fn:seconds-from-duration($duration) * 1000 | |
| return xs:integer($days + $hours + $minutes + $seconds) | |
| }; | |
| local:milliseconds-since-epoch(fn:current-dateTime()) | 
Sure! Notice, too, @ndw's use of xs:unsignedLong which might help with very large numbers like 1472502093491.
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Very nice! I first saw this in Norm Walsh's OAuth library, at https://github.com/ndw/XQuery-OAuth/blob/master/oauth.xqy#L40, and applied it in my adaptation at https://gist.github.com/joewiz/5929809#file-oauth-xq-L92.