How to display date and time inside a form #markup? I want to retrive a UNIX epoch (as returned by the PHP function time()) and display it as a formatted date as part of a text (i.e. a #markup element) in a form.  This is not a field where the user is supposed to enter a date. It is just showing the current date and time in a human readable format inside the form.

Is know that I can get a human readable date and time from a Unix epoch with the PHP date() function.

However, I am looking for the "Drupal" way of doing this. I think this means that I should display the date and time in the short format set by the site manager under Home » Administration » Configuration » Regional and language.

Is there a way to do this (or is there another way that is condidered "the Drupal way")?

Edit: Function format_date()  turned out to be the right answer.  It depends on a set of format variables (e.g. date_format_short) being set.  If this variable is undefined, you only get the US-centric formats hard-coded into format_date().  The confusing bit is that when you visit the  Home » Administration » Configuration » Regional and language admin page, it shows you some formats (and I therefore errenously assumed that these formats were those that were defined for the site). But these formats are not defined until you press Save configuration on that page.
Sounds like you want to use the format_date() function.

$now = time();
$date = format_date($now, 'short');


You can use it with any of the date formats that are defined in your system, or you can pass in a custom date string.