strptime

Formatting Dates in R (Non-standard format)

二次信任 提交于 2019-11-29 16:09:11
Not new to R or formatting dates in R and wouldn't be asking this question but I am having seriously strange behavior and in the last 2 hours am no closer to resolving it. I have a dataset which I have imported and want to format the date/time column using as.POSIXct . The date is a non-standard format and I've applied what I know to be the proper formatting. Here is a small part of the data that I am having trouble with. Code just after. Problem is that there are 4 NA's starting at "2015-03-08 02:00:00 PST" . What gives? This seems completely random as it happens no where else in any of the

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

做~自己de王妃 提交于 2019-11-29 15:14:17
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); Using this free, open source C++11/14 library , here is another way to deal with parsing fractional seconds: #include "tz.h" #include <iostream> #include <sstream> int main() {

How to parse str(my_datetime) using strptime ?

假装没事ソ 提交于 2019-11-29 14:37:36
This is the default string representation of a datetime: >>> from datetime import datetime, timezone >>> dt = datetime(2017, 1, 1, tzinfo=timezone.utc) >>> print(dt) 2017-01-01 00:00:00+00:00 What is the correct format string to parse that with datetime.strptime ? That is, what goes in place of the '???' to see the following result: >>> from dateutil.parser import parse >>> parse(date_str) == datetime.strptime('???', date_str) True Note that str(d) is documented as being equivalent to d.isoformat(' ') . This starts with %Y-%m-%d %H:%M:%S ( 2017-01-01 00:00:00 ), but then: Either has nothing or

How do I plot only the time portion of a timestamp including a date?

≯℡__Kan透↙ 提交于 2019-11-29 12:12:08
问题 So I have a set of timestamps like this: datetime<-c("2011-09-28 03:33:00", "2011-08-24 13:41:00", "2011-09-19 16:14:00", "2011-08-18 11:01:00", "2011-09-17 06:35:00", "2011-08-15 12:48:00") I want to make a histogram of only the times. What I did was to split the column at the space to get only the times, then convert back to a POSIXct object in order for qplot to plot it: library(ggplot2, stringr) qplot(as.POSIXct(strptime((str_split_fixed(as.character(time), " ", 2)[,2]), "%H:%M:%S")))

What does the “p” in strptime stand for?

北城余情 提交于 2019-11-29 10:53:49
问题 There is a strptime function in many language libraries (C, Python, Ruby, PHP, PERL, etc.). It seems to be based on the Open Group's specification for time.h. I understand 'str' stands for string, and 'time' obviously stands for time, but what does the 'p' stand for? Parse? Pointer? Print? Every time I reach for the strptime() function, I have a mental blank, and have to look up the name in a manual. I figure if I finally worked out what it stood for, perhaps I would have a chance of

Convert unicode to datetime proper strptime format

梦想与她 提交于 2019-11-29 06:18:51
问题 I am trying to convert a unicode object to a datetime object. I read through the documentation: http://docs.python.org/2/library/time.html#time.strptime and tried datetime.strptime(date_posted, '%Y-%m-%dT%H:%M:%SZ') but I get the error message ValueError: time data '2014-01-15T01:35:30.314Z' does not match format '%Y-%m-%dT%H:%M:%SZ' Any feedback on what is the proper format? I appreciate the time and expertise. 回答1: You can parse the microseconds: from datetime import datetime date_posted =

Date time conversion and extract only time

匆匆过客 提交于 2019-11-29 01:28:12
Want to change the class for Time to POSIXlt and extract only the hours minutes and seconds str(df3$Time) chr [1:2075259] "17:24:00" "17:25:00" "17:26:00" "17:27:00" ... Used the strptime function df33$Time <- strptime(df3$Time, format = "%H:%M:%S") This gives the date/time appended > str(df3$Time) POSIXlt[1:2075259], format: "2015-08-07 17:24:00" "2015-08-07 17:25:00" "2015-08-07 17:26:00" ... Wanted to extract just the time without changing the POSIXlt class. using the strftime function df3$Time <- strftime(df3$Time, format = "%H:%M:%S") but this converts the class back to "char" - > class

How to remove unconverted data from a Python datetime object

匆匆过客 提交于 2019-11-29 01:07:43
I have a database of mostly correct datetimes but a few are broke like so: Sat Dec 22 12:34:08 PST 20102015 Without the invalid year, this was working for me: end_date = soup('tr')[4].contents[1].renderContents() end_date = time.strptime(end_date,"%a %b %d %H:%M:%S %Z %Y") end_date = datetime.fromtimestamp(time.mktime(end_date)) But once I hit an object with a invalid year I get ValueError: unconverted data remains: 2 , which is great but im not sure how best to strip the bad characters out of the year. They range from 2 to 6 unconverted characters . Any pointers? I would just slice end_date

Is R superstitious regarding POSIXct data type

老子叫甜甜 提交于 2019-11-28 14:33:35
For a project, I was converting strings to POSIXct format using strptime function. x <- strptime("2016-03-13 02:56:16", "%Y-%m-%d %H:%M:%S") class(x) [1] "POSIXlt" "POSIXt" x + 3600 [1] NA Although class(x) results in "POSIXlt" "POSIXt" , doing x + 3600 , I get NA If I do a similar procedure for 2017 with the same month, day, hour, minute, second, it works! x <- strptime("2017-03-13 02:56:16", "%Y-%m-%d %H:%M:%S") class(x) [1] "POSIXlt" "POSIXt" x + 3600 [1] "2017-03-13 03:56:16 EDT" Looking back at my data, I see a list of dates where there will be a problem in date conversion! [1] "2016-03

AM/PM string is not properly recognized by strptime

℡╲_俬逩灬. 提交于 2019-11-28 13:30:55
I have encountered something unexpected while working with the function strptime(). The format of the date I have consists of "1/22/2013 11:00:00 P.M" . The format I am using for this is "%m/%d/%Y %I:%M:%S %p". The code is as follows. strptime("1/22/2013 11:00:00 p.m",format="%m/%d/%Y %I:%M:%S %p") [1] NA but if I use strptime("1/22/2013 11:00:00 pm",format="%m/%d/%Y %I:%M:%S %p") [1] "2013-01-22 23:00:00" I get the appropriate result. So does this feature lack in strptime to detect p.m and its variations such as p.m. etc in place of PM or pm. Is this a bug in R ? The version of R I am using R