Rafay
Rafay

Reputation: 99

Convert a iOS formatted timeto php timestamp

I have a string as "18 Jul 2014 11 59 PM". How to convert it to php timestamp format like 1404728913? Thanks in advance….

Upvotes: 0

Views: 404

Answers (2)

codester
codester

Reputation: 37189

You can use NSDateFormatter to convert date in to UTC timestamp

NSString *str          =   @"18 Jul 2014 11 59 PM";
NSDateFormatter *dateFormatter  =   [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"dd MMM yyyy hh mm a"];
NSDate *yourDate                =   [dateFormatter dateFromString:str];
NSLog(@"%@",@([yourDate timeIntervalSince1970]));

Give output 1405708140 which is UTC timstamp

Upvotes: 1

datagutten
datagutten

Reputation: 163

Add a : between the hour and minute and strtotime can read it. Something like this:

$timestamp = strtotime(preg_replace('/(.+)([0-9]{2}) ([0-9]{2})/','$1$2:$3',$string));

Upvotes: 0

Related Questions