Python Forum
Unsupported datetime format code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unsupported datetime format code
#1
Hi,

I am using python 3.12 and I would like to parse string as '2025:092:43200' into a datetime object.
2025 is the year (%Y), 092 is the day of the year (%j) and 43200 is the second of the day.
The last one, second of the day, is not supported by strptime and strftime so I have to parse my date into a datetime object manually.

I wonder if this format is planned to be supported. It is used in SINEX (Solution INdependent EXchange) file format.
Reply
#2
quick search and I found https://pypi.org/project/gnssanalysis/
The package itself may be useful for you, but anyway, it has helper functions for different date formats, incl. this one.

EDIT: searching for GNSS on PyPI and there are several more packages to work with GNSS files
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
You could check it here: https://anavs.com/support/time-converter/

from datetime import datetime as DateTime
from datetime import timezone as TimeZone
from datetime import timedelta as TimeDelta


def parse_gnss(dt: str) -> DateTime:
    year, day_of_year, second_of_day = map(int, dt.split(":"))
    mm, ss = divmod(second_of_day, 60)
    hh, mm = divmod(mm, 60)
    return DateTime(year, 1, 1, hh, mm, ss, tzinfo=TimeZone.utc) + TimeDelta(days=day_of_year - 1)


gnss = '2025:092:43200'
dt = parse_gnss(gnss)

print(gnss, "=>", dt)
Output:
2025:092:43200 => 2025-04-02 12:00:00+00:00
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#4
With Pendulum can do it like this.
import pendulum

def parse_gnss(s: str, tz="UTC") -> pendulum.DateTime:
    y, d, sod = map(int, s.split(':'))
    return (pendulum.datetime(y, 1, 1, tz=tz).add(days=d-1, seconds=sod))

pdt = parse_gnss('2025:092:43200')
print(pdt)
Output:
2025-04-02 12:00:00+00:00
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question [SOLVED] [datetime.strptime] ValueError: time data 'foo' does not match format 'bar' Winfried 1 3,223 Jan-02-2025, 02:09 AM
Last Post: lyly19
  An unexplainable error in .format statement - but only in a larger piece of code? ToniE 4 2,446 Sep-05-2023, 12:50 PM
Last Post: ToniE
  Review my code: convert a HTTP date header to a datetime object stevendaprano 1 5,325 Dec-17-2022, 12:24 AM
Last Post: snippsat
  Unsupported Format Character Led_Zeppelin 2 14,040 Sep-20-2022, 01:46 PM
Last Post: deanhystad
  How to get datetime from numeric format field klllmmm 3 3,375 Nov-06-2021, 03:26 PM
Last Post: snippsat
  Exporting dataframes to excel without loosing datetime format Rafa 0 2,126 Oct-27-2021, 10:42 AM
Last Post: Rafa
  Datetime format issue with z sks3286 2 10,311 Apr-07-2020, 12:26 PM
Last Post: sks3286
  Please suggest python code to format DNA sequence FASTA file rajamdade 4 5,181 Oct-24-2019, 04:36 AM
Last Post: rajamdade
  TypeError: unsupported operand type(s) for -: 'datetime.datetime' and 'str' findbikash 2 12,853 Sep-18-2019, 08:32 AM
Last Post: buran
  Change format of datetime Jonas85 6 5,804 Feb-05-2019, 03:47 PM
Last Post: Jonas85

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020