Is there any function/code snippet to retrieve the unix time stamp of the comment on a post? The WordPress default function comment_time();
returns the time of the post in 12hr format (not helpful).
Leave a Reply
You must be logged in to post a comment.
Use:
Regards.
I know you’ve already selected an answer, but just a note based on your comments: there’s a
human_time_diff()
function in WordPress. http://codex.wordpress.org/Function_Reference/human_time_diffThis deserves a new answer, because the answer is simple.
This quote can be found on the wordpress codex here
This information is super important because PHP has the following formatting tag
'U'
The complete list can be found here.
In other words. The answer to this question is:
comment_time('U');
Perhaps this wasn’t the case in 2011, but it is in 2016.
Not sure about how or why you need the unix time stamp.
You can get the ISO 8601 time stamp by using
This will output something like this
It may not be the unix timestamp, but at least you can use that to convert to a unix timestamp with php if you need to.
Here is a PHP function to convert to UNIX timestamp. Taken from google calendar for simplepie plugin.
Update
If you want to get the relative time for comments, there is an easier way than trying to work out the time stamp in unix and doing all these conversions.
Here are 2 functions I am using in the theme framework I am building that will do the job for you.
First add this to the theme functions.
}
Now you can get a relative time for any date format in worpdress.. either posts or comments.
For comments you can do something like this in the comments code.
Or for post date, use this inside the loop.
From what I understand you want to do, this will work. It outputs the date and time as number of days, hours etc relative to today.
eg:
45 seconds ago, or 1 day 1hr ago.. etc