【问题标题】:How to store timestamp in mysql database with timezone which sent by iphone app如何将时间戳存储在 mysql 数据库中,其中包含 iphone 应用程序发送的时区
【发布时间】:2012-10-24 09:48:18
【问题描述】:

我正在开发一个 iPhone 应用程序,它需要将时间数据与客户端时区一起存储在远程 mysql 数据库中。 这是通过调用 php web 服务并将数据存储在 mysql 数据库中来实现的。查找用户时区并发送到网络服务的最佳方式是什么。

编辑:

 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"];

如何使用客户端时区在 MySql 数据库中保存时间戳。有没有其他方法。

【问题讨论】:

  • 这是一个通知应用程序,我的问题是在特定时间发送电子邮件。如果我从 iPhone 存储时间戳,它将与网络服务器时间不同。

标签: php mysql objective-c web-services timezone


【解决方案1】:
SET time_zone = 'America/New_York'; 

这可以在 insert 之前更改 mysql db .execute 的时区设置。如果你想知道 php 中的当前时区,你可以使用date_default_timezone_get

【讨论】:

  • 如何将时区发送到网络服务
【解决方案2】:

Date().getTimezoneOffset() 这会对你有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-02
    • 2012-10-04
    • 2023-04-09
    • 1970-01-01
    • 2015-09-25
    • 2011-09-25
    • 1970-01-01
    相关资源
    最近更新 更多