date localization in iphone - iphone

I need to localize the date. i tried with following code but its giving wrong thing.
For Example if my locale is "US" if i take date like(06 August 2011, 10:55 A.M.) from date picker and store in database then after i changed to locale to "Dutch" its working fine, it converts into dutch like (06 augustus 2011 10:55)
If i take date from date picker like (06 augustus 2011 10:55) for locale "Dutch" then I am changing to locale to "US" its display like(06 July 2011 10:55 A.M.),but it should be like(06 August 2011 10:55 A.M.).
I use below code for get date local date from string:
NSDate *past = [NSDate dateWithNaturalLanguageString:#"06 augustus 2011 10:55" locale: [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]];
please help out me

You're going about this the wrong way. You should not store localized strings in your database, just store the actual -date returned from UIDatePicker.
Use NSDate all the time, and only when you display to the user do you use a NSDateFormatter to show the date in the user's appropriate locale.
Hope this helps!

Related

Change date format on dart

I am retrieving a date from api in this format, e.g "2020-03-02". But i need to a render it as this format e.g, "Tuesday, March,2020". I have been unable to find consice solution to this with flutter. Any help?
Use intl plugin
print(DateFormat('EEEE, MMM, yyyy').parse(dateString)); // prints Tuesday, mar, 2020
//OR
print(DateFormat('yyyy, MMM, EEEE').parse(dateString)); // prints 2020, mar, Tuesday

Moment JS setting TimeZone to EST - alloy/moment

I am using momentjs in alloy framework in Appcelerator. My api returns the date as - 2017-09-06T12:03:00.000Z I am using below code to format this date into readable form -
var dt = moment(record.createddate);
$.dateValue.text = moment(dt).format('lll');
But the output I get is - Sep 6, 2017 5:33 PM, which is not correct as the date saved in db and returned from api is EST and the date getting displayed is GMT+0530. How should i format this date so that I get the correct date value?
I guess, somewhere in your code, the moment's default timezone is set to GMT+0530. Something like moment.tz.setDefault('Asia/Colombo') could do this.
You can define in what timezone you want to display your date. This should work for you :
moment('2017-09-06T12:03:00.000Z').tz("Etc/GMT").format('lll')
Or if you want the value I suggested in the comments :
moment('2017-09-06T12:03:00.000Z').tz("Etc/GMT-2").format('lll')
For more informations about moment.js timezones, you can check the moment.js timezone docs.
Hope this helps !

How can I shift timezone of Date object created in local timezone to target timezone in GWT client?

How can I shift timezone of Date object created in local timezone to target timezone?
Here is what I need. I want web-client to pick a date using DatePicker but resulting Date object should look like as if it was picked in another timezone. Since there is no way to tell DatePicker to do that I have to manually shift date.
For example it's Apr 6th 2012 2:42AM in California right now. Created Date will be in UTC-7 timezone. I want to have Date object with Apr 6th 2012 2:42AM in Europe/Moscow timezone.
Here is I do it right now:
final TimeZoneConstants constTz = GWT.create(TimeZoneConstants.class);
final TimeZone timeZoneMsk = TimeZone.createTimeZone(constTz.europeMoscow());
final TimeZone timeZoneCali = TimeZone.createTimeZone(constTz.americaLosAngeles());
Date curTime = new Date();
DateTimeFormat dateTimeFormat = DateTimeFormat.getFullDateTimeFormat();
Date mskTime = new Date(curTime.getTime() - (curTime.getTimezoneOffset() - timeZoneMsk.getStandardOffset()) * 60 * 1000);
String strLocal = dateTimeFormat.format(curTime, timeZoneCali); // Friday, 2012 April 06 02:42:59 Pacific Daylight Time
String strMsk = dateTimeFormat.format(mskTime, timeZoneMsk); // Friday, 2012 April 06 02:42:59 Moscow Standard Time
There are two problems with this method:
If you ask me it looks pretty bizarre.
Timezone in mskTime is still -0007. I wonder if it can cause any problems in future when I deserialize this object from Google App Engine datastore.
Or should I just produce string with full date of local Californian time, replace timezone in string and then generate new Date by calling DateTimeFormat.parse() ? It looks pretty hacky too...
Also what do you think of JodaTime for GWT ? Is it stable enough for production ?
Your code looks about right. Using DateTimeFormat.parse might make the intention clearer to a casual reader. It's not very often that you are given timezones A and B and one Date object, and you have to produce a new Date object that, when formatted in B, has the same time as the original when formatted in A.
Timezone in mskTime is still -0007. I wonder if it can cause any problems in future when I deserialize this object from Google App Engine datastore.
No, there can be no problems. Remember that a Date object represents a universal point in time not bound to a timezone. When it's April 6 14:40 in Moscow, it's April 6 03:40 in California, so the Date objects are equal.

NSDate from string...?

I am working on calendar application. In this i have some issues with date format..
I am conflicting with two types of date formats..
one is -- 02-10-2010
second is - 02 Oct, 2010
but i want these formats be same..
any methods to convert from one format to second or second to first..
i searched date from string..but i cannot understand...
Check out NSDateFormatter.

iphone NSDate NSDateFormatter to a ceratin format

i want to convert my NSDate to a certain format which is:
"Wednesday, December, 2, 2009"
does anybody know what is the corresponding format string to that date example?
appreciate your help!
Look here for date formatting syntax, looks like what you need would be #"%A, %B,%d,%Y"