date-parsing

Correct Date format to use for GsonBuilder Date Format

心不动则不痛 提交于 2020-06-27 16:21:23
问题 My client sends me a date in "2019-11-22T16:16:31.0065786+00:00" format. I am getting the following error: java.text.ParseException: Unparseable date: "2019-11-22T16:16:31.0065786+00:00" The date format that I am using is: new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSSZ") .create(); Please let me know which format to use. 回答1: This format can be handled by DateTimeFormatter.ISO_ZONED_DATE_TIME instance of DateTimeFormatter . It is a part of Java Time package which was released

Convert Date String to another Date string with different format

一曲冷凌霜 提交于 2020-06-23 07:06:06
问题 I need to convert an string date with format yyyyMMdd to a date string with format MM/dd/yyyy . Which is the best to do it? I'm doing this: DateTime.ParseExact(dateString, "yyyyMMdd", CultureInfo.InvariantCulture).ToString("MM/dd/yyyy") But I'm not sure, i think there must be a better way. What do you think? 回答1: What you are doing is fine. Probably you can improve it by using DateTime.TryParseExact and on successful parsing, format the DateTime object in other format. string dateString =

Speed up date columns conversion (pandas) from string to datetime

别等时光非礼了梦想. 提交于 2020-05-17 07:56:29
问题 I am working with a large .csv file in python and its date column is 'str'. I am using the following code to convert the records in this column to datetime. df[date_column].fillna('1900-01-01',inplace=True) df[date_column] = df[date_column].apply(lambda x : pd.to_datetime(x, format = datetime_format)) But this seems to be taking quite a long time to execute. Any suggestions on how to handle this is welcomed. Thanks. 回答1: When you read your csv , you can using parse_dates df = pd.read_csv(

Read csv with dd.mm.yyyy in Python and Pandas

情到浓时终转凉″ 提交于 2020-03-18 12:33:19
问题 I am reading a csv file with German date format. Seems like it worked ok in this post: Picking dates from an imported CSV with pandas/python However, it seems like in my case the date is not recognized as such. I could not find any wrong string in the test file. import pandas as pd import numpy as np %matplotlib inline import matplotlib.pyplot as plt from matplotlib import style from pandas import DataFrame style.use('ggplot') df = pd.read_csv('testdata.csv', dayfirst=True, parse_dates=True)

Parse a Python datetime string in Javascript

為{幸葍}努か 提交于 2020-01-23 01:29:05
问题 I need to parse a Python-generated datetime string into a Javascript Date object. I went the simplest route: In Python: dstring = str(mydate) example dstring = '2012-05-16 19:20:35.243710-04:00' In Javascript (with datejs library): d = new Date(dstring); This gets me a correct date object in Chrome, but an "Invalid Date" error in Firefox and Safari (on Mac). 回答1: You need to parse the string into a JS Date. The Date constructor is not enough. Maybe you should consider using a library such as

How can I make a DateTimeFormatter that accepts trailing junk?

て烟熏妆下的殇ゞ 提交于 2020-01-21 06:51:54
问题 I'm retrofitting old some SimpleDateFormat code to use the new Java 8 DateTimeFormatter . SimpleDateFormat , and thus the old code, accepts strings with stuff in them after the date like "20130311nonsense". The DateTimeFormat I created throws a DateTimeParseException for these strings, which is probably the right thing to do, but I'd like to maintain compatibility. Can I modify my DateTimeFormat to accept these strings? I'm currently creating it like this: DateTimeFormatter.ofPattern(