in Education by
I want' to parse dates in this format, but ignore parts of the string. 'Wed, 27 Oct 1770 22:17:00 GMT' From what I have gathered, datetime does not support time zones very well. Which is fine, I really just want to ignore the timezone part of the string, without having to do string manipulation on it. Is there something I can replace %Z with below to say "any string here" and parse dates as such? Also, I don't understand why it will parse timezones like PST, GMT but not EST. It doesn't seem to attach tzinfo in any case anyways, not sure what types of string its really looking for the %Z portion. >>> import datetime >>> y = datetime.datetime.strptime('Wed, 27 Oct 1770 22:17:00 GMT', '%a, %d %b %Y %H:%M:%S %Z') >>> y = datetime.datetime.strptime('Wed, 27 Oct 1770 22:17:00 PST', '%a, %d %b %Y %H:%M:%S %Z') >>> y = datetime.datetime.strptime('Wed, 27 Oct 1770 22:17:00 EST', '%a, %d %b %Y %H:%M:%S %Z') Traceback (most recent call last): File "", line 1, in File "/opt/brazil-pkg-cache/packages/Python/Python-2.5.1.17.1/RHEL5_64/DEV.STD.PTHREAD/build/lib/python2.5/_strptime.py", line 331, in strptime (data_string, format)) ValueError: time data did not match format: data=Wed, 27 Oct 1770 22:17:00 EST fmt=%a, %d %b %Y %H:%M:%S %Z Note: dateutil is not an option for me, I want to support numerous formats and can't allow dateutil to accidentally interpret dates wrong. (i.e. dateutil seems to take a guess when it sees dates like 01/02/2010, Feb 1? or Jan 2?). I basically want to just try accepting formats I specify in an order until I get a match. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Have you actually looked at the docs for dateutil? dateutil.parser.parse() does have arguments which let you control the precedence in its format guesser and it also has an ignoretz=True argument. If that's not enough, there's probably some class you can override to implement your own precedence rules. Of course, if not, you probably will have to resort to string parsing since Python's strptime() implementation calls the underlying C implementation to resolve the timezone names. (I don't know why it isn't understanding EST for you, but it's probably system-wide and not a problem on some systems)

Related questions

0 votes
    How can someone parse a numeric string like "121.5555" to it's corresponding float value 121.5555? or parse a ... str to an int. Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    I am trying to convert a string into date format in Google Sheet. I've tried different formulas but ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    I need to parse RFC 3339 strings like "2008-09-03T20:56:35.450686Z" into Python's datetime type. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 12, 2022 in Education by JackTerrance
0 votes
    I need to parse RFC 3339 strings like "2008-09-03T20:56:35.450686Z" into Python's datetime type. I have found ... best way to do this? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    What is the parameter of the method Date.parse()? (a) date (b) string (c) datestring (d) string ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 21, 2021 in Education by JackTerrance
0 votes
    y = " \{ Hi\} {0} " print y.format(43) it's showing an error: Key Error: Hi\\ I want to print the output from the above syntax: {Hi} 43 Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    I am trying to write a program that reads data from hundreds of YAML files repetitively and stores certain ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I have many rows in a database that contains XML and I'm trying to write a Python script that will go through ... the XML using Python? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    This my my JSON: { "maps": [ { "id": "AT", "iscategorical": "0" }, { "id": "AT", "iscategorical": "0 ... the values, How can I do it? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    Why can't we Python parse this JSON data?...
asked Jan 11, 2021 by JackTerrance
0 votes
    I am inserting JSON string into table, than on listing page in View inside foreach loop I want to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    how to parse query string in node.js lambda?...
asked Dec 10, 2020 in Technology by JackTerrance
0 votes
    I have a data which looks like EX:992215:SHOW:CMS016:000335:ESP:15:EUR:Euro:4:14:01/05/2009 :30 ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
...