如何使用nsdateformatter委内瑞拉 [英] how to use nsdateformatter to Venezuela
问题描述
我想在日历上安排一个日期,其中包含开始时间和结束时间,如果时区在美国,一切正常,更改日期不起作用,我需要它委内瑞拉我应该做什么,因为我放置generica,无论何时在任何地方服务我的时区?
I'm trying to schedule a date on the calendar, which has a start time and an end time, everything works fine if the time zone is in the U.S., and the date the change does not help and I need it to Venezuela what should I do as I place generica, to serve me anywhere no matter the time zone?
这里我把代码作为数据,带来我,格式。
here I leave the code as data and bring me as I make the date format.
comes the date in the following format: 12/10/2012 05:00 pm
EKEvent* event = [EKEvent eventWithEventStore:eventStore];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeZone:[NSTimeZone localTimeZone]];
[dateFormatter setDateFormat:@"dd/MM/yyyy hh:mm:ss a"];
horafin = [dateFormatter dateFromString:inicio];
horafin = [horafin dateByAddingTimeInterval:3600];
horainicio = [dateFormatter dateFromString:inicio];
[dateFormatter release];
NSString *ti=[[NSString alloc]initWithString:title];
NSLog(@"");
event.title =@"juego";
event.startDate = horainicio;
event.endDate = horafin;
event.URL = [NSURL URLWithString:@"http://pagina.com"];
event.notes = ti;
event.allDay = NO;
vc.event = event;
vc.editViewDelegate = self;
[self presentViewController:vc animated:YES completion:nil];
事件日历只有在您更改时区时才会正确通知我,因为我没有
The event calendar call me correctly only fails when you change the time zone, as I did not take the date correctly I can do?
推荐答案
我使用以下代码来获取所需的时区转换datetime:
I use following code to get desired timezone-converted datetime:
- (NSString *) getUTCDate : (NSString *) inputDate
{
NSDateFormatter *utcDateFormatter = [[NSDateFormatter alloc] init];
[utcDateFormatter setDateFormat:@"dd-MMM-yyyy HH:mm:ss Z"];
[utcDateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
// [utcDateFormatter setTimeZone :[NSTimeZone timeZoneForSecondsFromGMT: 0]];
// utc format
NSDate *dateInUTC = [utcDateFormatter dateFromString: inputDate];
return dateInUTC;
}
其中 dateInUTC
GMT时区的日期。
where dateInUTC
is the date in GMT timezone.
您需要在 [NSTimeZone timeZoneWithName:@UTC]
中替换您自己的时区, 。
You need to replace your own timezone in call [NSTimeZone timeZoneWithName:@"UTC"]
and it should work.
这篇关于如何使用nsdateformatter委内瑞拉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!