Php 如何使用现有脚本将时间戳变量转换为可读的?(提供)

Php 如何使用现有脚本将时间戳变量转换为可读的?(提供),php,mysql,Php,Mysql,如何使用此脚本将变量传递到时间转换而不是当前时间? 我的变量是$article['timestamp']并且它是一个MySQL时间戳 <?php date_default_timezone_set('Europe/Athens'); setlocale(LC_TIME, 'el_GR.UTF-8'); echo strftime('%A '); $greekMonths = array('Ιανουαρίου','Φεβρουαρίου','Μαρτίου','Απριλ

如何使用此脚本将变量传递到时间转换而不是当前时间? 我的变量是
$article['timestamp']并且它是一个MySQL时间戳

<?php
  date_default_timezone_set('Europe/Athens');

  setlocale(LC_TIME, 'el_GR.UTF-8');
  echo strftime('%A ');
  $greekMonths = array('Ιανουαρίου','Φεβρουαρίου','Μαρτίου','Απριλίου','Μαΐου','Ιουνίου','Ιουλίου','Αυγούστου','Σεπτεμβρίου','Οκτωβρίου','Νοεμβρίου','Δεκεμβρίου');
  $greekDate = date('j') . ' ' . $greekMonths[intval(date('m'))-1] . ' ' . date('Y');
  echo $greekDate;
?>

只需将您的时间戳转换为unix时间戳,并将其输入
date()
函数:

date_default_timezone_set('Europe/Athens');
$article['timestamp'] = '2015-03-07 15:14:24';
$unix = strtotime($article['timestamp']); // to unix
setlocale(LC_TIME, 'el_GR.UTF-8');
echo strftime('%A ');
$greekMonths = array('Ιανουαρίου','Φεβρουαρίου','Μαρτίου','Απριλίου','Μαΐου','Ιουνίου','Ιουλίου','Αυγούστου','Σεπτεμβρίου','Οκτωβρίου','Νοεμβρίου','Δεκεμβρίου');

// then use the unix timestamp and feed it into the date function
$greekDate = date('j', $unix) . ' ' . $greekMonths[intval(date('m', $unix))-1] . ' ' . date('Y', $unix);
echo $greekDate;

请举例说明:输入、电流输出和预期值output@Rizier123您好,我已经编辑了我的问题,您从未在代码中使用过
$article['timestamp']
。但如果我没弄错的话,你只想把这个月换成希腊月份,并把它改成预期的格式?@Rizier123是的,没错。我发布的代码显示信息,但在当前date@Xalloumokkelos当然,很高兴这件事透露了一些情况
date_default_timezone_set('Europe/Athens');
$article['timestamp'] = '2015-03-07 15:14:24';
$unix = strtotime($article['timestamp']); // to unix
setlocale(LC_TIME, 'el_GR.UTF-8');
echo strftime('%A ');
$greekMonths = array('Ιανουαρίου','Φεβρουαρίου','Μαρτίου','Απριλίου','Μαΐου','Ιουνίου','Ιουλίου','Αυγούστου','Σεπτεμβρίου','Οκτωβρίου','Νοεμβρίου','Δεκεμβρίου');

// then use the unix timestamp and feed it into the date function
$greekDate = date('j', $unix) . ' ' . $greekMonths[intval(date('m', $unix))-1] . ' ' . date('Y', $unix);
echo $greekDate;