dateformatter

TimeZone Date Formatting Issue

折月煮酒 提交于 2021-02-17 05:34:49
问题 I'm trying to get a date from a string with multiple time zones, It works without any problems if the API returns zones with abbreviations like CST or UTC but it fails if it returns EET let timeString = "17:32 (EET)" let formatter = DateFormatter() formatter.dateFormat = "HH:mm (zzz)" let time = formatter.date(from: timeString) // return nil Any idea what is the issue might be?! 回答1: Probably because there is more than one timezone that matches the timezone abbreviation or the date formatter

Dart parse date with +0000

懵懂的女人 提交于 2020-05-17 05:46:36
问题 I am using the Twitter api for getting tweets in a Flutte App. The api returns a formatted date like this: Wed Jun 12 00:08:35 +0000 2019 DateTime formatTwitterDate() { final format = DateFormat('EEE MMM dd hh:mm:ss +0000 yyyy'); //todo failed to resolve +0000 return format.parse(this); } This is the only formatter I got working. How can I support +0000? 回答1: Used this javascript implementation and transformed it to a DartExtension https://stackoverflow.com/a/2611438/5115254 extension

Dart parse date with +0000

﹥>﹥吖頭↗ 提交于 2020-05-17 05:46:26
问题 I am using the Twitter api for getting tweets in a Flutte App. The api returns a formatted date like this: Wed Jun 12 00:08:35 +0000 2019 DateTime formatTwitterDate() { final format = DateFormat('EEE MMM dd hh:mm:ss +0000 yyyy'); //todo failed to resolve +0000 return format.parse(this); } This is the only formatter I got working. How can I support +0000? 回答1: Used this javascript implementation and transformed it to a DartExtension https://stackoverflow.com/a/2611438/5115254 extension

Dart parse date with +0000

回眸只為那壹抹淺笑 提交于 2020-05-17 05:46:24
问题 I am using the Twitter api for getting tweets in a Flutte App. The api returns a formatted date like this: Wed Jun 12 00:08:35 +0000 2019 DateTime formatTwitterDate() { final format = DateFormat('EEE MMM dd hh:mm:ss +0000 yyyy'); //todo failed to resolve +0000 return format.parse(this); } This is the only formatter I got working. How can I support +0000? 回答1: Used this javascript implementation and transformed it to a DartExtension https://stackoverflow.com/a/2611438/5115254 extension

Convert date string into proper format

六月ゝ 毕业季﹏ 提交于 2019-12-31 07:47:53
问题 I am getting a response from a server and there is a date string I need to convert into a date: Thu Jun 29 07:15:25 +0000 2017 I am trying to convert the string into a human readable format. Can anyone suggest how to convert this string into date? 回答1: You need to parse the date string into a Date object using a DateFormatter , then create a string from that Date using another DateFormatter with the output format you want to use. let created_at = "Thu Jun 29 07:15:25 +0000 2017" let df =

DateFormatter returns unexpected date for Timezone

余生长醉 提交于 2019-12-29 09:19:08
问题 I've read multiple posts about this, and most were due to not setting a specific Timezone and the system getting the current one. My scenario is slightly different and gives unexpected results, so I'll try to explain in detail. I'm dealing with a backend that returns dates split into a date and a time, stored as an Integer value. For example, a return value could be 131006 , which would translate to 13:10:06 . I know that this backend always returns the date in UTC . I cast this to a String

Show dates on seaborn heatmap

帅比萌擦擦* 提交于 2019-12-29 08:20:34
问题 I am trying to create a heat map from pandas dataframe using seaborn library. Here, is the code: test_df = pd.DataFrame(np.random.randn(367, 5), index = pd.DatetimeIndex(start='01-01-2000', end='01-01-2001', freq='1D')) ax = sns.heatmap(test_df.T) ax.xaxis.set_major_locator(mdates.MonthLocator()) ax.xaxis.set_minor_locator(mdates.DayLocator()) ax.xaxis.set_major_formatter(mdates.DateFormatter('%b')) ax.xaxis.set_minor_formatter(mdates.DateFormatter('%d')) However, I am getting a figure with

Dateformatter returns nil date

不问归期 提交于 2019-12-25 03:13:50
问题 I'm trying to add 3 hours to the date I get back from the server. publication.DateTime is a string and I need to first convert it to date before doing the manipulation. Here's my attempt: let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ" dateFormatter.locale = Locale(identifier: "en_US_POSIX") let date = dateFormatter.date(from:(publication.DateTime)!) //date is nil here let calendar = Calendar.current let components = calendar.dateComponents([.year,

DateFormatter returns nil

强颜欢笑 提交于 2019-12-13 11:24:12
问题 Why does DateFormatter return nil? I think the string format matches? let dateString = ("01/05/2017")! let dateFormatter = DateFormatter() dateFormatter.timeZone = TimeZone.current dateFormatter.dateFormat = "dd/MMM/yyyy" let dateObj = dateFormatter.date(from: dateString) After executing the code above, the dateObj is nil. 回答1: For month you need to use MM because MMM is used when you having month in the format like Jan , Feb , Mar and so on. So your dateFormat should be dd/MM/yyyy . let