string-to-datetime

Converting String Format Date for Date Object

情到浓时终转凉″ 提交于 2019-12-24 22:24:16
问题 I am getting a Date format in String as Output like this. Fri May 18 00:00:00 EDT 2012 I need to Convert this to a Date Object. What approach shall I use? Thank you. This is the program i used. import java.util.*; import java.text.*; public class DateToString { public static void main(String[] args) { try { DateFormat formatter ; Date date ; formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss 'EDT' yyyy "); date = (Date)formatter.parse("Fri May 18 00:00:00 EDT 2012"); String s = formatter

String to date not working properly [duplicate]

帅比萌擦擦* 提交于 2019-12-13 10:42:38
问题 This question already has answers here : Change date format in a Java string (18 answers) Closed 5 years ago . I am trying from half an hour to convert string to date by using following code: SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-dd"); Date lastCharged = dateFormat.parse(lastChargeDate); Every time I run this code the date returned by the system is Sun Dec 29 00:00:00 PKT 2013 Even if i changed the date manually same is the response by the system. Any help in this regard

Pandas to_datetime not working for null values

我们两清 提交于 2019-12-11 07:44:26
问题 Right, I'm going to be as clear as I can. Here's my dataframe called base_varlist2 . completion_date_latest completion_date_original customer_birth_date_1 \ 0 07/10/2004 17/05/1996 04/02/1963 1 16/02/2004 16/02/2004 31/10/1968 2 25/03/2004 25/03/2004 18/09/1960 3 10/02/2004 10/02/2004 18/04/1972 4 03/08/2010 25/05/2004 12/09/1960 5 16/04/2004 16/04/2004 27/08/1975 6 05/04/2004 05/04/2004 02/02/1971 7 26/03/2004 26/03/2004 05/05/1959 8 29/07/2004 29/07/2004 10/10/1960 9 14/06/2004 14/06/2004

Pandas Inconsistent date-time format

本小妞迷上赌 提交于 2019-12-10 23:38:47
问题 I started using pandas library about a fortnight back. Learning the new features. I would appreciate help on the following problem. I have a column with dates in mixed format. These are the 2 formats present mm/dd/yyyy dd/mm/yyyy An extract from the dataset :- Dates 6/5/2016 7/5/2016 7/5/2016 7/5/2016 9/5/2016 9/5/2016 9/5/2016 9/5/2016 5/13/2016 5/14/2016 5/14/2016 I am struggling to convert these to a common format. I tried using pandas's 'to_datetime'. It does not work. I am also not sure

In python pandas, how can I convert this formatted date string to datetime

拜拜、爱过 提交于 2019-12-10 18:24:00
问题 I have tried several ways of using to_datetime , but so far I can only get it to return the dtype as "object" pd.to_datetime(pd.Series(['28Dec2013 19:23:15']),dayfirst=True) The return from this command is: 0 28Dec2013 19:23:15 dtype: object 回答1: You can pass a format parameter to the to_datetime function. >>> import pandas as pd >>> df = pd.to_datetime(pd.Series(['28Dec2013 19:23:15']),format="%d%b%Y %H:%M:%S",dayfirst=True) >>> df 0 2013-12-28 19:23:15 dtype: datetime64[ns] 回答2: In case you

Using strptime %z with special timezone format

一笑奈何 提交于 2019-12-06 23:31:47
问题 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

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

How do I cast dd/mm/yyyy string into date in BigQuery?

走远了吗. 提交于 2019-11-29 09:16:41
问题 I have 3 columns 1. dd/mm/yyyy (stored as a string) 2. app_id and #downloads of apps I have to find unique ids of apps downloaded within a week. Thank you 回答1: You can convert your dd/MM/yyyy strings into BigQuery timestamps using something like the following: SELECT TIMESTAMP(year + '-' + month + '-' + day) as output_timestamp FROM ( SELECT REGEXP_EXTRACT(input_date, '.*/([0-9]{4})$') as year, REGEXP_EXTRACT(input_date, '^([0-9]{2}).*') as day, REGEXP_EXTRACT(input_date, '.*/([0-9]{2})/.*')

Why is pandas.to_datetime slow for non standard time format such as '2014/12/31'

坚强是说给别人听的谎言 提交于 2019-11-27 13:04:44
I have a .csv file in such format timestmp, p 2014/12/31 00:31:01:9200, 0.7 2014/12/31 00:31:12:1700, 1.9 ... and when read via pd.read_csv and convert the time str to datetime using pd.to_datetime , the performance drops dramatically. Here is a minimal example. import re import pandas as pd d = '2014-12-12 01:02:03.0030' c = re.sub('-', '/', d) %timeit pd.to_datetime(d) %timeit pd.to_datetime(c) %timeit pd.to_datetime(c, format="%Y/%m/%d %H:%M:%S.%f") and the performances are: 10000 loops, best of 3: 62.4 µs per loop 10000 loops, best of 3: 181 µs per loop 10000 loops, best of 3: 82.9 µs per

Why is pandas.to_datetime slow for non standard time format such as '2014/12/31'

烈酒焚心 提交于 2019-11-26 15:52:16
问题 I have a .csv file in such format timestmp, p 2014/12/31 00:31:01:9200, 0.7 2014/12/31 00:31:12:1700, 1.9 ... and when read via pd.read_csv and convert the time str to datetime using pd.to_datetime , the performance drops dramatically. Here is a minimal example. import re import pandas as pd d = '2014-12-12 01:02:03.0030' c = re.sub('-', '/', d) %timeit pd.to_datetime(d) %timeit pd.to_datetime(c) %timeit pd.to_datetime(c, format="%Y/%m/%d %H:%M:%S.%f") and the performances are: 10000 loops,