Skip to main content
edited title
Link
Elie Masaad
  • 413
  • 1
  • 7
  • 21

Get Convert current time in m/from Unix timestamp to date format (d/m/y format)

added 270 characters in body
Source Link
Elie Masaad
  • 413
  • 1
  • 7
  • 21

In my custom module (.module) file, I am using:

$current_time = \Drupal::time()->getCurrentTime();
date_default_timezone_set('GMT');

to get the current date... However, the date value is returned in int A Unix timestamp like: 1556582116

I have tried so far something like:

$current_time = \Drupal::time()->getCurrentTime();
$timenow = $current_time->format('Y-m-d H:i:s');

or

$current_time = \Drupal::time()->getCurrentTime('d');

to get only the day value... but with no success

How can I return the date value in the format of: D/M/Y like: 30/04/2019 or 30/Apr/19

In my custom module (.module) file, I am using:

$current_time = \Drupal::time()->getCurrentTime();
date_default_timezone_set('GMT');

to get the current date... However, the date value is returned in int A Unix timestamp like: 1556582116

How can I return the date value in the format of: D/M/Y like: 30/04/2019 or 30/Apr/19

In my custom module (.module) file, I am using:

$current_time = \Drupal::time()->getCurrentTime();
date_default_timezone_set('GMT');

to get the current date... However, the date value is returned in int A Unix timestamp like: 1556582116

I have tried so far something like:

$current_time = \Drupal::time()->getCurrentTime();
$timenow = $current_time->format('Y-m-d H:i:s');

or

$current_time = \Drupal::time()->getCurrentTime('d');

to get only the day value... but with no success

How can I return the date value in the format of: D/M/Y like: 30/04/2019 or 30/Apr/19

Source Link
Elie Masaad
  • 413
  • 1
  • 7
  • 21

Get current time in m/d/y format

In my custom module (.module) file, I am using:

$current_time = \Drupal::time()->getCurrentTime();
date_default_timezone_set('GMT');

to get the current date... However, the date value is returned in int A Unix timestamp like: 1556582116

How can I return the date value in the format of: D/M/Y like: 30/04/2019 or 30/Apr/19