gps周 python_从Python开始的几周以来的GPS时间?

def weeksecondstoutc(gpsweek,gpsseconds,leapseconds):

import datetime, calendar

datetimeformat = "%Y-%m-%d %H:%M:%S"

epoch = datetime.datetime.strptime("1980-01-06 00:00:00",datetimeformat)

elapsed = datetime.timedelta(days=(gpsweek*7),seconds=(gpsseconds+leapseconds))

return datetime.datetime.strftime(epoch + elapsed,datetimeformat)

weeksecondstoutc(1811,164196.732,16) ## --> '2014-09-22 21:36:52'

因此,从unix时间转换回GPS也需要关注闰秒:

def utctoweekseconds(utc,leapseconds):

""" Returns the GPS week, the GPS day, and the seconds

and microseconds since the beginning of the GPS week """

import datetime, calendar

datetimeformat = "%Y-%m-%d %H:%M:%S"

epoch = datetime.datetime.strptime("1980-01-06 00:00:00",datetimeformat)

tdiff = utc -epoch -datetime.timedelta(seconds=leapseconds)

gpsweek = tdiff.days // 7

gpsdays = tdiff.days - 7*gpsweek

gpsseconds = tdiff.seconds + 86400* (tdiff.days -7*gpsweek)

return gpsweek,gpsdays,gpsseconds,tdiff.microseconds

utctoweekseconds(datetime.datetime.strptime('2014-09-22 21:36:52',"%Y-%m-%d %H:%M:%S"),16)

## gives: (1811, 1, 164196,0)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值