In facebook or twitter time of post is changing every minute on every post.

Any idea how to make it?

Make a field in your database for each post, that records the time & date when it was posted.
Then you can make a function that returns the current datetime - the insertdatetime...
You round it off to whatever you want(ours, mins, seconds), and you just have to call that function than.

You mean send AJAX request every minute to php function that gets date and counts the difference?

yeah...But it's not a very efficient solution though...To make that much database calls is not really good for the performance of your website.
So i think it would be better to use a javascript solution instead of Ajax.
You can write the date time to a hidden field, and use a javascript function to update every X seconds / minute / ...
Take a look at this link:
If you enhance this script a bit, you'll get the result you want, with much better performance.