strptime

Converting date formats python - Unusual date formats - Extract %Y%M%D

不打扰是莪最后的温柔 提交于 2019-12-06 08:39:33
I have a large data set with a variety of Date information in the following formats: DAYS since Jan 1, 1900 - ex: 41213 - I believe these are from Excel http://www.kirix.com/stratablog/jd-edwards-date-conversions-cyyddd YYDayofyear - ex 2012265 I am familiar with python's time module, strptime() method, and strftime () method. However, I am not sure what these date formats above are called on if there is a python module I can use to convert these unusual date formats. Any idea how to get the %Y%M%D format from these unusual date formats without writing my own calculator? Thanks. You can try

Parsing date and timestamps in Python with time.strptime format

坚强是说给别人听的谎言 提交于 2019-12-06 03:57:36
问题 My cloud server logs time in this format: [17/Dec/2011:09:48:49 -0600] To read it into Python variables, I can say: >>>str = '17/Dec/2011:09:48:49 -0600' >>>import time >>>print time.strptime(str,"%d/%b/%Y:%H:%M:%S -0600") Result: time.struct_time(tm_year=2011, tm-mon=12, tm=mday=17, tm_hour=9, tm_min=48, tm_sec=49, tm_wday=5, tm_yday=351, tm_isdst=-1) or I can try >>>mytime = time.strptime(str,"%d/%b/%Y:%H:%M:%S -0600") >>>print mytime.tm_hour Result: 9 What does the -0600 do? I expected it

convert to date and strip time?

◇◆丶佛笑我妖孽 提交于 2019-12-05 13:06:39
I have some data that looks like this: dates <- structure(c(1L, 2L, 4L, 3L), .Label = c("Sat, 18 Nov 2017 00:00:00 GMT", "Thu, 16 Nov 2017 00:00:00 GMT", "Tue, 14 Nov 2017 00:00:00 GMT", "Wed, 15 Nov 2017 00:00:00 GMT"), class = "factor") I would like to convert it to a date format instead of having it as a factor. Additionally, I want to strip the 00:00:00 GMT because it is meaningless I tried lubridate but I'm having troubles with the format: library(lubridate) mdy(dates) Warning message: All formats failed to parse. No formats found. This looks like it is working: as.POSIXct(dates, format =

c/c++ strptime() does not parse %Z Timezone name

会有一股神秘感。 提交于 2019-12-05 10:29:46
I am new to C. When I practicing C to covert time sting to structure tm back and forth. I noticed some difference. Please advice what I did wrong. #include <string.h> #include <stdio.h> #include <time.h> /* test different format string to strptime " %A, %b %d, %X %z %Y " " %A, %b %d, %X %Z %Y " */ int main(int argc,char *argv[]) { char date[] = "6 Mar 2001 12:33:45"; char fmt[80]; struct tm tm; if (argc==1) return 0; strcpy(fmt,argv[1]); memset(&tm, 0, sizeof(struct tm)); if (strptime(date,"%d %b %Y %H:%M:%S",&tm)==NULL) printf("error\n"); char buf[128]; strftime(buf, sizeof(buf), fmt, &tm);

using strptime converting string to time but getting garbage

自作多情 提交于 2019-12-05 07:48:51
I have a problem with using strptime() function in c++. I found a piece of code in stackoverflow like below and I want to store string time information on struct tm. Although I should get year information on my tm tm_year variable, I always get a garbage.Is there anyone to help me ? Thanks in advance. string s = dtime; struct tm timeDate; memset(&timeDate,0,sizeof(struct tm)); strptime(s.c_str(),"%Y-%m-%d %H:%M", &timeDate); cout<<timeDate.tm_year<<endl; // in the example below it gives me 113 cout<<timeDate.tm_min<<endl; // it returns garbage **string s will be like "2013-12-04 15:03"** cout<

Using strptime %z with special timezone format

本秂侑毒 提交于 2019-12-05 04:11:54
I am working with .csv data that was exported from Teradata. Several columns were originally timestamps with timezones, so after loading the .csv in R I'd like to convert these columns (which are loaded as strings) to POSIXlt or POSIXct. I am using strptime , but the format of the timezone from the .csv file does not match what strptime is expecting. For example, it expects -0400 but the .csv has the format -04:00 where a colon separates the hours and minutes. I can remove the colon, but this is an extra step and complication I'd like to avoid if possible. Is there a way to tell strptime to

Compiler gets warnings when using strptime function (C)

可紊 提交于 2019-12-05 03:44:53
Typing man strptime it sais that this function needs to have declared _XOPEN_SOURCE and included time.h header. I did it. But, when I try to compile my code I get: ./check.c:56: warning: implicit declaration of function ‘strptime’ Look at my code: int lockExpired(const char *date, const char *format, time_t current) { struct tm *tmp = malloc(sizeof(struct tm *)); time_t lt; int et; strptime(date, format, tmp); lt = mktime(tmp); et = difftime(current, lt); if (et < 3600) return -et; return 1; } Also the function declaration is: char *strptime(const char *s, const char *format, struct tm *tm);

error in getting the correct date using strptime in R

China☆狼群 提交于 2019-12-04 06:35:47
问题 I'm using strptime to extract date and the result is a wrong year Where is the error in the below code: strptime('8/29/2013 14:13', "%m/%d/%y") [1] "2020-08-29 PDT" What are the other ways to extract date and time as separate columns. The data I have is in this format - 8/29/2013 14:13 I want to split this into two columns, one is 8/29/2013 and the other is 14:13 . 回答1: You have a four digit year so you need to use %Y strptime('8/29/2013 14:13', "%m/%d/%Y" ) [1] "2013-08-29 CEST" Do you

Strptime with timezones and jq

穿精又带淫゛_ 提交于 2019-12-04 05:34:38
问题 Not sure what I am doing wrong here getting_data | gunzip | jq -r '.time_field | strptime("%Y-%m-%dT%H:%M:%S.%fZ")' The error comes back as such: jq: error (at <stdin>:0): date "2018-03-13T14:00:17.1614661Z" does not match format "%Y-%m-%dT%H:%M:%S.%fZ" The desired output would be 2018-03-13 14:00:17 回答1: The issue is not the timezone, but the nanoseconds field; %f is not available in standard strptime for C. If you know your format won't change, there's no particular reason to use strptime

Parsing string dates in ruby such as “28-May-10”

假装没事ソ 提交于 2019-12-04 04:29:40
问题 I tried parsing using Date.parse("28-May-10").to_s Returns 0010-5-28 (which is 2000 years off!) How can I get ruby to interpret the two digit year properly. There are plenty of string to date conversion tricks out there on google but most handle digit months as opposed to "May". 回答1: I prefer Date.strptime for this task: require 'date' puts Date.strptime("28-May-10", "%d-%b-%y") #2010-05-28 来源: https://stackoverflow.com/questions/9727898/parsing-string-dates-in-ruby-such-as-28-may-10