Susitha
Susitha

Reputation: 3349

How to store timestamp in mysql database with timezone which sent by iphone app

I am developing a iPhone app which need to store time data with client time zone in a remote mysql database. This is doing by calling a php web service and store data in mysql database. What is the best way to find user timezone and send to web service.

edit:

 NSTimeZone *tzone  = [NSTimeZone defaultTimeZone];
 NSTimeInterval timeInt = [dateTime timeIntervalSince1970 ];
 NSNumber *timeStamp=[NSNumber numberWithInt:timeInt];

 NSString *zone = [tzone name];
 NSURL *url = [NSURL URLWithString:@"http://localhost/mytask/"];

 ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:[NSString stringWithFormat:@"%@", timeStamp] forKey:@"task_time_stamp"];
[request setPostValue:zone forKey:@"task_time_zone"];

How to save time stamp in MySql database with client timezone. is there any other approach.

Upvotes: 1

Views: 444

Answers (2)

Yasas Rangika
Yasas Rangika

Reputation: 359

Date().getTimezoneOffset() this will help you.

Upvotes: 1

Arun Killu
Arun Killu

Reputation: 14253

SET time_zone = 'America/New_York'; 

this can change the time zone setting of mysql db .execute before insert . if u want to know the current time-zone in php u can use date_default_timezone_get .

Upvotes: 1

Related Questions