Reputation: 99
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
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
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