Converting date string to/from date of different locale - swift

Taking the Japanese locale for example,
converting 2017-06-08T14:41:56+0000 to a format EEEE, MMM d, yyyy under the locale ja will give:
木曜日, 6月 8, 2017
but converting 木曜日, 6月 8, 2017 to a date object using the format EEEE, MMM d, yyyy and locale does not work.
Is there a way to handle date/time string conversions for unique locales?

Related

Flutter custom date format

I am facing issue while formatting the date to custom format.
I need to convert date yyyy-MM-dd HH:mm:ss ===> EEEE, MMM dd, yyyy
For example I am getting date from server 27-10-2022 11:02:50, and I need to convert it to Thursday, October 27, 2022
Getting Date format is "dd-MM-yyyy HH:mm:ss" and the desire format will be "EEEE, MMMM dd, yyyy"
final data = "27-10-2022 11:02:50";
final format = DateFormat("dd-MM-yyyy HH:mm:ss");
final DateTime result = format.parse(data);
print(result); //2022-10-27 11:02:50.000
final newFormatter = DateFormat("EEEE, MMMM dd, yyyy");
final newFormatString = newFormatter.format(result);
print(newFormatString); // Thursday, October 27, 2022
I am using intl package
Just checked in flutter docs. Your date format is not good. For converting string to date.
The following date format is required,
"2012-02-27 13:27:00"
"2012-02-27 13:27:00.123456789z"
"2012-02-27 13:27:00,123456789z"
"20120227 13:27:00"
"20120227T132700"
"20120227"
"+20120227"
"2012-02-27T14Z"
"2012-02-27T14+00:00"
"-123450101 00:00:00 Z": in the year -12345.
"2002-02-27T14:00:00-0500": Same as "2002-02-27T19:00:00Z"
And you can convert that into the format like below
var date1 = DateFormat('dd-MM-yyyy hh:mm:ss').parse("27-10-2022 11:02:50");
var date2 = DateFormat('yyyy-MM-dd hh:mm:ss').format(date1);
print( DateFormat('EEEE, MMMM dd, yyyy').format(date2));
please try this, hope you will get the idea,
print(DateFormat('dd-MM-yyyy HH:mm:ss').parse('27-10-2022 11:02:50'));

Moment JS not parsing date in Croatian locale

I am trying to parse the date string in lang 'HR' (Croatian locale) 20. svibnja 2021 into moment date. Result should be 20-may-2021 but it is formatting to 20-Jan-2021.
moment('20. svibnja 2021', 'DD MMMM YYYY', 'HR') or
moment('20. svibnja 2021', 'LLL', 'HR')
Not sure why this is happening

Logstash: How to match the timezone ID 'CET' in a date filter pattern?

In Logstash, I want to convert a string into a timestamp using the date filter. The string looks follows:
Fri Nov 05 06:24:28.651 CET 2021
I've tried the following pattern to no avail:
date {
match => [ "syslog_timestamp", "EEE MMM dd HH:mm:ss.SSS ZZZ yyyy"]
locale => "en_US"
timezone => "Europe/Berlin"
target => "syslog_timestamp"
}
This is confusing since Logstash is said to use the Joda library and Joda in turn says 'CET' is a legal timezone ID. I confirmed the results by testing the Jody library v2.10.13 directly in a Java application.
How to parse CET/CEST in the date filter?
Since time zone names (z) cannot be parsed and ZZZ still wouldn't match the daylight-saving variant 'CEST' according to Joda's documentation, I worked around this issue in Logstash by handling the timezone code as text and passing multiple patterns with the standard time zone and daylight-saving time zone to the filter:
match => [ "syslog_timestamp", "EEE MMM dd HH:mm:ss.SSS 'CET' yyyy", "EEE MMM dd HH:mm:ss.SSS 'CEST' yyyy"]

Grails dataBinding not working on default marshalled grails date

It seems that Grails by default is providing a date marshalled in JSON as "EEE MMM dd HH:mm:ss z yyyy" (e.g: Sat Jan 05 00:02:00 CET 2019)
If this (string) date is used in a domain creation activity (create an instance of the same domain class with this string-date as the date), Grails will not recognize it by default (although I think it should logically accept it).
Pooblem is that the Data Format "EEE MMM dd HH:mm:ss z yyyy" is not recognized in the
grails.databinding.dateFormats = [
'EEE MMM dd HH:mm:ss z yyyy',
'dd/MM/yyyy HH:mm:ss',
'dd/MM/yyyy',
'yyyy-MM-dd HH:mm:ss',
'yyyy-MM-dd HH:mm:ss.S',
"yyyy-MM-dd'T'hh:mm:ss'Z'",
'dd.mm.yyyy',
'MMddyyyy'
]
or in the #BindingFormat as well.
It looked like, to parse the 'EEE MMM dd HH:mm:ss z yyyy', the locale is also needed.
Something like:
def dateFormat = "EEE MMM dd HH:mm:ss z yyyy";
SimpleDateFormat smpDF= new SimpleDateFormat( dateFormat, Locale.UK );
Is there a way to pass the locate so grails binds this date as it is from the string?
Update: This is Grails 3.3.9

Date Formatting in Objective C (iOS SDK)

Hope you can help. I am importing the current GMT time for an iPhone App. This is being retrieved via a JSON web service.
I believe I have the correct formatter string however I am getting a different date (time is still correct) when I try to format the date I've retrieved. The JSON date is formatted like this: Sun, 15 May 2011 20:35:31 +0000
In the example below strGMT is the date in the format I've just mentioned.
This is the code I'm using to get retrieved date into my code:
NSLog(#"Current GMT: %#", strGMT);
NSDateFormatter *gmtFormatter=[[NSDateFormatter alloc] init];
[gmtFormatter setDateFormat:#"EEE, dd MMM YYYY HH:mm:ss VVVV"];
//THIS IS NOT REFORMATTING CORRECTLY HERE
NSDate *gmtDateTime=[gmtFormatter dateFromString:strGMT];
NSLog(#"Current Formatted GMT Date: %#", gmtDateTime);
The log is showing the following:
Current GMT: Sun, 15 May 2011 20:35:31 +0000
Current Formatted GMT Date: 2010-12-26 20:35:31 +0000
Have I not got the formatting string correct? Any ideas why it's gone from 15 May 2011 (today) to 26th December 2010?
Kind regards
Paul
The correct format string is #"EEE, dd MMMM yyyy HH:mm:ss VVVV"