Questions tagged [strptime]

`strptime` reads the time from the string s using the timeformat specifiers and converts it into seconds since the year 2000.

779 questions
33
votes
5 answers

unknown timezone name in R strptime/as.POSIXct

Where can I find a list of all legal time names for R function as.POSIXct? as.POSIXct("1970-01-01",tz="CST") generates a warning that "CST" (Central Standard Time) is unknown.
ahala
  • 333
  • 1
  • 3
  • 4
28
votes
6 answers

Date time conversion and extract only time

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 =…
Antex
  • 1,364
  • 4
  • 18
  • 35
25
votes
9 answers

Strptime with Timezone

I have a String which I parse with DateTime.strptime. The Timezone of the Date in the String is CET but Ruby creates an UTC DateTime object which of course has an offset of 2hrs. Currently I'm working around the issue with…
Nicolas
  • 1,828
  • 6
  • 23
  • 34
24
votes
4 answers

Thread-safe equivalent to python's time.strptime()?

Something I wrote throws a lot of AttributeError exceptions when using time.strptime() inside a thread. This only seems to happen on Windows (not on Linux) but whatever- upon a'Googling, it seems that time.strptime() isn't considered thread-safe. Is…
Wells
  • 10,415
  • 14
  • 55
  • 85
23
votes
5 answers

Converting a string to a formatted date-time string using Python

I'm trying to convert a string "20091229050936" into "05:09 29 December 2009 (UTC)" >>>import time >>>s = time.strptime("20091229050936", "%Y%m%d%H%M%S") >>>print s.strftime('%H:%M %d %B %Y (UTC)') gives AttributeError: 'time.struct_time' object…
Josh
  • 7,936
  • 5
  • 41
  • 63
21
votes
5 answers

python datetime strptime wildcard

I want to parse dates like these into a datetime object: December 12th, 2008 January 1st, 2009 The following will work for the first date: datetime.strptime("December 12th, 2008", "%B %dth, %Y") but will fail for the second because of the suffix…
hoju
  • 28,392
  • 37
  • 134
  • 178
20
votes
5 answers

How to convert timestamp into string in Python

I have a problem with the following code. I get an error "strptime() argument 1 must be str, not Timestamp" I guess that what I should do is to convert date from timestamp to string but I do not know what to do. class TweetAnalyzer: def…
Rachele Povelato
  • 201
  • 1
  • 2
  • 7
19
votes
4 answers

str to time in python

time1 = "2010-04-20 10:07:30" time2 = "2010-04-21 10:07:30" How to convert the above from string to time stamp? I need to subtract the above timestamps time2-time1.
Rajeev
  • 44,985
  • 76
  • 186
  • 285
19
votes
1 answer

TypeError: must be string, not datetime.datetime when using strptime

I am trying to write a function in Python 2.7 that converts a series of numbers into a valid date. So far, it all works apart form the conversion. Here is the relevant code: import datetime def convert_date(x,y,z): orig_date =…
Fake Name
  • 813
  • 2
  • 9
  • 17
19
votes
3 answers

A faster strptime?

I have code which reads vast numbers of dates in 'YYYY-MM-DD' format. Parsing all these dates, so that it can add one, two, or three days then write back in the same format is slowing things down quite considerably. 3214657 14.330 0.000 …
John Mee
  • 50,179
  • 34
  • 152
  • 186
18
votes
2 answers

strptime, as.POSIXct and as.Date return unexpected NA

When I try to parse a timestamp in the following format: "Thu Nov 8 15:41:45 2012", only NA is returned. I am using Mac OS X, R 2.15.2 and Rstudio 0.97.237. The language of my OS is Dutch: I presume this has something to do with it. When I try…
Hemmik
  • 183
  • 1
  • 5
17
votes
2 answers

Convert unicode to datetime proper strptime format

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…
bbrooke
  • 2,267
  • 10
  • 33
  • 41
16
votes
2 answers

Python - converting strings in an array to dates

I have read an array of strings from a TXT file and saved it as an array (of over thousand values) using such a line: dates = np.genfromtxt('filename.txt', delimiter=";", usecols=(0), dtype=None) Next, I would like to convert strings into dates. I…
kaksat
  • 709
  • 1
  • 7
  • 18
15
votes
2 answers

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

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…
William Gunn
  • 2,925
  • 8
  • 26
  • 22
14
votes
4 answers

unconverted data remains: .387000 in Python

I have a datetime that is a string I read from a text file. I want to trim the extra milliseconds off of it, but I want to convert it to a datetime variable first. This is because it may be in different formats depending on what is in the text…
TheBigOnion
  • 615
  • 3
  • 9
  • 19
1
2
3
51 52