Created
June 20, 2014 11:11
-
-
Save jdswinbank/e382ea707ca92f2510dc to your computer and use it in GitHub Desktop.
This file contains 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
from pyrap.quanta import quantity | |
import time | |
# Unix time starts at 00:00:00 coordinated universal time on 1 January 1970. | |
unix_epoch = quantity("1970-01-01T00:00:00") | |
def unix_to_mjds(unix_time): | |
return unix_time + unix_epoch.get_value('s') | |
def mjds_to_unix(mjds): | |
return mjds - unix_epoch.get_value('s') | |
def s2d(seconds): | |
# seconds to days | |
return seconds / (24 * 60 * 60.0) | |
def d2s(days): | |
# days to seconds | |
return days * (24 * 60 * 60.0) | |
if __name__ == "__main__": | |
print "The Unix epoch starts when MJD is %d seconds" % ( | |
unix_epoch.get_value('s')) | |
now_unix = time.time() | |
print "\nThe current Unix time is %d" % (now_unix,) | |
print "That's equivalent to an MJD of %f s (%f d)" % ( | |
unix_to_mjds(now_unix), s2d(unix_to_mjds(now_unix))) | |
now_pyrap = quantity('today').get_value('s') | |
print "\nThe current MJD is %f s (%f d)" % ( | |
now_pyrap, now_pyrap / (24 * 3600)) | |
print "That's equivalent to a unix time of %d" % ( | |
mjds_to_unix(now_pyrap),) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment