Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Date to UNIX timestamp

I'm having a date format of Jun 26, '12.
strtotime() converts proper date string, and this string results in a blank output. This can be solved but I can only think of ugly ways of doing it.

Any ideas for converting this date format to UNIX timestamp elegantly?

like image 346
user1425322 Avatar asked Jul 04 '12 07:07

user1425322


People also ask

How do I convert a date to time stamp?

Use the getTime() method to convert a date to a timestamp, e.g. new Date(). getTime() . The getTime method returns the number of milliseconds elapsed between the 1st of January, 1970 and the given date.

How do I convert date to epoch?

Convert from human-readable date to epoch long epoch = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse("01/01/1970 01:00:00").getTime() / 1000; Timestamp in seconds, remove '/1000' for milliseconds. date +%s -d"Jan 1, 1980 00:00:01" Replace '-d' with '-ud' to input in GMT/UTC time.

How is Unix timestamp calculated?

The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z).


2 Answers

How about this strtotime('Jun 26,12');

like image 199
user850234 Avatar answered Sep 20 '22 20:09

user850234


I used DateTime::createFromFormat works well for me.. more info here.

like image 24
vikramaditya234 Avatar answered Sep 20 '22 20:09

vikramaditya234