strptime

why strptime for two digit year for 69 returns 1969 in python?

為{幸葍}努か 提交于 2021-02-11 14:47:34
问题 Look at the following code, def expdate(date): _exp_date = datetime.strptime(date, "%m%y") >>> expdate('1268') 2068-12-01 00:00:00 >>> expdate('1269') 1969-12-01 00:00:00 Optionally how to actually overcome this and get 2070 ? I'll be checking only using 2 digits years. 回答1: Python depends on the platform’s C library, which generally doesn’t have year 2000 issues, since all dates and times are represented internally as seconds since the epoch. Functions accepting a struct_time generally

Python: Parse timestamp string with 7 digits for microseconds to datetime

混江龙づ霸主 提交于 2021-02-11 07:18:05
问题 I have a timestamp string that looks like this: 2019-02-16T10:41:20.6080000+01:00 I have to parse it to datetime. Because there are 7 instead of 6 digits for microseconds the following format does not match: timestamp = "2019-03-14T14:37:37.000000+01:00" parsed_timestamp = datetime.datetime.strptime(timestamp, "%Y-%m-%dT%H:%M:%S.%f%z") #ValueError: time data '2019-03-14T14:37:37.0000000+01:00' does not match format '%Y-%m-%dT%H:%M:%S.%f%z' How can I parse this format? 回答1: Using dparser:

Python: Parse timestamp string with 7 digits for microseconds to datetime

…衆ロ難τιáo~ 提交于 2021-02-11 07:15:41
问题 I have a timestamp string that looks like this: 2019-02-16T10:41:20.6080000+01:00 I have to parse it to datetime. Because there are 7 instead of 6 digits for microseconds the following format does not match: timestamp = "2019-03-14T14:37:37.000000+01:00" parsed_timestamp = datetime.datetime.strptime(timestamp, "%Y-%m-%dT%H:%M:%S.%f%z") #ValueError: time data '2019-03-14T14:37:37.0000000+01:00' does not match format '%Y-%m-%dT%H:%M:%S.%f%z' How can I parse this format? 回答1: Using dparser:

Why does strptime() behave differently on OSX and on Linux?

故事扮演 提交于 2021-02-10 03:57:05
问题 Consider this program: #include <stdio.h> #include <time.h> int main() { struct tm t; strptime("2015-08-13 12:00:00", "%F %T", &t); printf("t.tm_wday = %d\n", t.tm_wday); return 0; } Under OSX, this is what I obtain: $ gcc test_strptime.c $ ./a.out t.tm_wday = 0 But on Linux, this is what I get: $ gcc test_strptime.c $ ./a.out t.tm_wday = 4 Why is the bahaviour different? I would expect the day of the week to be well defined, given the data and the time of the day? 回答1: The Linux (glibc) and

Why does strptime() behave differently on OSX and on Linux?

空扰寡人 提交于 2021-02-10 03:54:45
问题 Consider this program: #include <stdio.h> #include <time.h> int main() { struct tm t; strptime("2015-08-13 12:00:00", "%F %T", &t); printf("t.tm_wday = %d\n", t.tm_wday); return 0; } Under OSX, this is what I obtain: $ gcc test_strptime.c $ ./a.out t.tm_wday = 0 But on Linux, this is what I get: $ gcc test_strptime.c $ ./a.out t.tm_wday = 4 Why is the bahaviour different? I would expect the day of the week to be well defined, given the data and the time of the day? 回答1: The Linux (glibc) and

How to convert decimal time to time format [duplicate]

这一生的挚爱 提交于 2021-02-08 06:56:23
问题 This question already has an answer here : Outputting difftime as HH:MM:SS:mm in R (1 answer) Closed 3 years ago . I would like to calculate the difference between two time-sets. I can do this, but I only get the difference in decimals and I would like to know how to convert them to format as in "Minutes:Second". So, I have the minutes and the seconds as characters: video_begin <- c("8:14", "4:47", "8:27", "4:59", "4:57", "7:51", "6:11", "5:30") video_end <- c("39:08", "47:10", "49:51", "44

datetime.strptime(‘2017-01-12T14:12:06.000-0500’,'%Y-%m-%dT%H:%M:%S.%f%Z')

怎甘沉沦 提交于 2021-02-07 03:54:08
问题 I've been trying to convert this specific date format to a string in Python like so: datetime.strptime(‘2017-01-12T14:12:06.000-0500’,'%Y-%m-%dT%H:%M:%S.%f%Z') But it doesn't work. What am I doing wrong? 回答1: Solution for Python 2.7 From the comments it became clear that OP needs a solution for Python 2.7. Apparently, there's no %z in strptime for python 2.7 even though the documentation claims the contrary, the raised error is ValueError: 'z' is a bad directive in format '%Y-%m-%dT%H:%M:%S

datetime.strptime(‘2017-01-12T14:12:06.000-0500’,'%Y-%m-%dT%H:%M:%S.%f%Z')

坚强是说给别人听的谎言 提交于 2021-02-07 03:53:19
问题 I've been trying to convert this specific date format to a string in Python like so: datetime.strptime(‘2017-01-12T14:12:06.000-0500’,'%Y-%m-%dT%H:%M:%S.%f%Z') But it doesn't work. What am I doing wrong? 回答1: Solution for Python 2.7 From the comments it became clear that OP needs a solution for Python 2.7. Apparently, there's no %z in strptime for python 2.7 even though the documentation claims the contrary, the raised error is ValueError: 'z' is a bad directive in format '%Y-%m-%dT%H:%M:%S

Converting time format to numeric with R

℡╲_俬逩灬. 提交于 2021-01-21 07:42:09
问题 In most cases,we convert numeric time to posixct format using R. However, sometimes, we want to compare which time point is earlier, then we would prefer the numeric time format. Thus, it's quite practical question to convert time format to numeric. For example,I have the data format like "2001-03-13 10:31:00", begin <- "2001-03-13 10:31:00" Using R, I want to figure out how to covert it into a numeric, e.g. the Julian time, something like the passing seconds between 1970-01-01 00:00:00 and