What is the substitute of 'posixtime' which starts counting from 6th Jan, 1980

1 回表示 (過去 30 日間)
SA
SA 2021 年 3 月 31 日
コメント済み: SA 2021 年 3 月 31 日
With the following code I get the TimeStamp is 08-Sep-2020 16:50:00 (This is correct/required)
gps_seconds=1283619000;
gps_start=datetime(1980,1,6,'TimeZone', 'UTC');
TimeStamp=gps_start+seconds(gps_seconds)
However, the following line give me the time time format of 04-Sep-2010 16:50:00 (10 years earlier because 'posixtime' starts counting from 1.1.1970).
TimeStamp = datetime(gps_seconds, 'convertfrom', 'posixtime','TimeZone', 'UTC');
Can anyone may help ...is there any substitute of 'posixtime' which starts counting from 6th Jan, 1980?

採用された回答

Steven Lord
Steven Lord 2021 年 3 月 31 日
編集済み: Steven Lord 2021 年 3 月 31 日
Is there some reason your first code segment is unacceptable for your application?
gps_seconds=1283619000;
gps_start=datetime(1980,1,6,'TimeZone', 'UTC');
TimeStamp=gps_start+seconds(gps_seconds)
TimeStamp = datetime
08-Sep-2020 16:50:00
Do you want one call to datetime without having to add on the seconds later?
gps_seconds=1283619000;
TimeStamp2 = datetime(1980,1,6,0, 0, gps_seconds,'TimeZone', 'UTC')
TimeStamp2 = datetime
08-Sep-2020 16:50:00
Or you could use 'epochtime'.
TimeStamp3 = datetime(gps_seconds,'ConvertFrom','epochtime','Epoch',gps_start, ...
'TimeZone', 'UTC')
TimeStamp3 = datetime
08-Sep-2020 16:50:00
Let's check.
TimeStamp == TimeStamp2
ans = logical
1
TimeStamp == TimeStamp3
ans = logical
1
  1 件のコメント
SA
SA 2021 年 3 月 31 日
Thanks, Steven for the support. There is no reason to unaccept the 1st part of the code. However, I do believe there are a lot of smart ways, people may think. In this case, I appreciate your approach.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGravitation, Cosmology & Astrophysics についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by