如何使用 nsdateformatter 到委内瑞拉 [英] how to use nsdateformatter to Venezuela
问题描述
我正在尝试在日历上安排一个日期,该日期有开始时间和结束时间,如果时区在美国,一切正常,而更改日期没有帮助,我需要它委内瑞拉 当我放置仿制药时我该怎么做,无论时区如何都可以为我服务?
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?
推荐答案
我使用以下代码来获取所需的时区转换日期时间:
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屋!