strptime

How Do I Parse a Date Time String That Includes Fractional Time?

匆匆过客 提交于 2020-01-10 05:11:10
问题 I have a date time string: 20:48:01.469 UTC MAR 31 2016 I would like to convert this string representation of time to a struct tm using strptime , but my format string isn't working. Is there a format specifier for fractional seconds? Perhaps %S , %s , or something else? Code snippet is below: tm tmbuf; const char *str = "20:48:01.469 UTC MAR 31 2016" const char *fmt = "%H:%M:%s %Z %b %d %Y"; strptime(str,fmt,&tmbuf); 回答1: Using this free, open source C++11/14 library, here is another way to

Converting Character String to Datetime

天大地大妈咪最大 提交于 2020-01-07 06:17:06
问题 I am trying to load a dataset into r and change the type of a column into datetime. strptime , as.POSIXct or as.Date for different cases should work; This is my code: a <- structure(list(DATE = c("01/01/2011 12:00:00", "01/02/2011 12:00:00", "01/03/2011 12:00:00", "01/04/2011 12:00:00", "01/05/2011 12:00:00", "01/06/2011 12:00:00"), VAL = c(65.34447917, 65.23983333, 65.03183333, 64.89107292, 64.83333333, 64.848625), id = c("VT1-1", "VT1-1", "VT1-1", "VT1-1", "VT1-1", "VT1-1")), .Names = c(

Find time difference in days with R

寵の児 提交于 2020-01-06 20:06:46
问题 Does anyone have a clue why in the following code I get "Time difference of NA secs" result? I was expecting to get the difference of days, like the It did for "2015-01-06". today <- Sys.Date() today <- strptime(today, "%Y-%m-%d") date <- "2015-01-06" date <- strptime(date, "%Y-%m-%d") today - date Time difference of 321 days Well done. But then... date <- "2015-10-18" date <- strptime(date, "%Y-%m-%d") today - date Time difference of NA secs Why secs? EDIT: Here is session info R version 3.2

Python custom datetime(?) format handling

回眸只為那壹抹淺笑 提交于 2020-01-06 17:09:35
问题 Let's say i have a string representing a time with number of day of the week: For example '52300', which means 5th day of week(Friday), 23 Hours 00 Minutes. How do i parse it to time or datetime object to add a timedelta(hours=3) and get it back to this strange format? Expected output is '60200' string. I have tried: tow_str = '52300' tow = datetime.datetime.strptime(tow_str, "%w%H%M") + datetime.timedelta(hours=3) print(tow.strftime("%w%H%M")) which returns '20200' instead of '60200' 回答1:

Python custom datetime(?) format handling

隐身守侯 提交于 2020-01-06 17:09:14
问题 Let's say i have a string representing a time with number of day of the week: For example '52300', which means 5th day of week(Friday), 23 Hours 00 Minutes. How do i parse it to time or datetime object to add a timedelta(hours=3) and get it back to this strange format? Expected output is '60200' string. I have tried: tow_str = '52300' tow = datetime.datetime.strptime(tow_str, "%w%H%M") + datetime.timedelta(hours=3) print(tow.strftime("%w%H%M")) which returns '20200' instead of '60200' 回答1:

PHP strptime format bug?

十年热恋 提交于 2020-01-05 01:41:14
问题 I am wrestling with a php 5.2.6 problem. An api we use returns dates in this format DDMMYYYYHHMM. Exactly that format, fixed length, no delimiters. However, in my experimentation, this format seems to break strptime, which returns a false (fail) when I feed it a date in this format. It can reproduced, at least on my system, with this example: $format = "%d%m%Y%H%M"; echo print_r(strptime(strftime($format,1225405967),$format),true); If I add any character between the date and the time, it

Speeding up datetime.strptime

社会主义新天地 提交于 2020-01-03 15:55:23
问题 I am using the following piece of code to extract a date from a string: try: my_date = datetime.strptime(input_date, "%Y-%m-%d").date() except ValueError: my_date = None If I run this 750,000 times, it takes 19.144 seconds (determined with cProfile). Now I replace this with the following (ugly) code: a= 1000 * int(input_date[0]) b= 100 * int(input_date[1]) c= 10 * int(input_date[2]) d= 1 * int(input_date[3]) year = a+b+c+d c= 10 * int(input_date[5]) d= 1 * int(input_date[6]) month = c+d c= 10

Speeding up datetime.strptime

旧时模样 提交于 2020-01-03 15:54:13
问题 I am using the following piece of code to extract a date from a string: try: my_date = datetime.strptime(input_date, "%Y-%m-%d").date() except ValueError: my_date = None If I run this 750,000 times, it takes 19.144 seconds (determined with cProfile). Now I replace this with the following (ugly) code: a= 1000 * int(input_date[0]) b= 100 * int(input_date[1]) c= 10 * int(input_date[2]) d= 1 * int(input_date[3]) year = a+b+c+d c= 10 * int(input_date[5]) d= 1 * int(input_date[6]) month = c+d c= 10

python convert datetime formatted string to seconds

旧城冷巷雨未停 提交于 2020-01-03 10:56:11
问题 I am trying to decode a date string to epoch but I have difficulties getting the timezone. This is the last modified date from Amazon S3 keys. time.strptime(key.last_modified, '%Y-%m-%dT%H:%M:%S.%Z') ValueError: time data u'2013-10-20T00:41:32.000Z' does not match format '%Y-%m-%dT%H:%M:%S.%Z' If I get rid of the timezone (.000Z) it works, but I need the timezone as well. 回答1: The .000Z is not recognized as a timezone offset. In fact, you have milliseconds and a timezone ( Z is UTC), and

Strange strptime behavior in R

不想你离开。 提交于 2019-12-31 03:05:18
问题 I experience very strange behaviour of strptime parsing. This is my R session on windows machine > R.Version()$version.string [1] "R version 2.15.2 (2012-10-26)" > a <- ( strptime( "29-MAR-13 02.26.53.000000000 AM" , "%d-%B-%y %I.%M.%OS %p" ) ) > str(a) POSIXlt[1:1], format: "2013-03-29 02:26:53" > # convert to double: doesn't work > as.double(a) [1] NA > b <- ( strptime( "29-MAR-13 04.26.53.000000000 AM" , "%d-%B-%y %I.%M.%OS %p" ) ) > #same as `a`, but another hour > str(b) POSIXlt[1:1],