Php 如果可能的话,我可以从时间戳中得到月份吗?

Php 如果可能的话,我可以从时间戳中得到月份吗?,php,timestamp,Php,Timestamp,当一张图片被上传到网站上时,我想在图片下面显示上传的月份。我在数据库中有一个时间戳字段 如果可能的话,我可以从时间戳中得到月份吗?我该怎么做 我试着用这个代码来做 <?php $query="SELECT * FROM magimgdes ORDER BY id DESC, time DESC " ; $result=mysql_query($query) OR DIE(mysql_error()); while($row=mysql_fetch_array($result)){

当一张图片被上传到网站上时,我想在图片下面显示上传的月份。我在数据库中有一个时间戳字段

如果可能的话,我可以从时间戳中得到月份吗?我该怎么做

我试着用这个代码来做

<?php $query="SELECT * FROM magimgdes ORDER BY id DESC, time DESC " ;

  $result=mysql_query($query) OR DIE(mysql_error());
  while($row=mysql_fetch_array($result)){
      $value1=$row['image'];
      $value3=$row['time'];
     ?>
  <img src="admin/upload/hompageimage/<?php echo $value1; ?>" width="180" height="195" alt="magimage" />

 <?php echo $value3;} ?></div>

“width=“180”height=“195”alt=“magimage”/
“time”字段是数据库中的时间戳字段


我只想回应这个月。

是的,你可以过得去


您可以使用date函数来实现这一点


首先,您需要将MySql日期时间格式转换为UNIX时间戳,为此,您可以使用
strotime
函数。然后,您可以使用许多函数来处理月份的提取,例如
getdate
函数

$timestamp = strtotime($row['time']); // Convert to unix time.
$info = getdate($timestamp); // Get the fields of a date (in an array).
$month = $info['mon']; // This is the element that contains the month.
echo $month; // This will print a number from 1 to 12.

数据库中的“时间戳”字段不明确。列类型是什么?或者您指的是UNIX时间戳?打印的是什么看起来像???请不要使用
mysql.*
函数来编写新代码。它们不再被维护,社区已经开始。请参阅?相反,您应该了解并使用或。如果您无法决定使用哪一个,将对您有所帮助。如果您选择PDO,。也请参阅添加更多关于为什么答案不能解决您的问题的信息在一个上面或把一个标记为已接受。
$timestamp = strtotime($row['time']); // Convert to unix time.
$info = getdate($timestamp); // Get the fields of a date (in an array).
$month = $info['mon']; // This is the element that contains the month.
echo $month; // This will print a number from 1 to 12.