打印后使用 PHP 格式化 DATETIME 列 [英] Format DATETIME column using PHP after printing

查看:77
本文介绍了打印后使用 PHP 格式化 DATETIME 列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我使用 DATETIME 作为我的数据库列.我正在尝试找到使用 PHP 格式化该行中保存的日期的最佳方法.我尝试使用 date() 但这只会打印当前日期.我的行看起来像:

Hey, I am using DATETIME for my column for my database. I am trying to find the best way to format this date held in the row using PHP. I tried using date() but that would just print the current date. My row looks something like:

$row['date_added']

有什么想法吗?

推荐答案

几个选项.

  1. 使用 MySQL 的 DATE_FORMAT 函数来格式化它.
  2. 使用 MySQL 的 UNIX_TIMESTAMP 获取时间戳的函数 PHP 的 date() 函数可以使用.
  3. 通过PHP的strtotime()函数运行MySQL DATETIME获取时间戳PHP的date()函数可以播放
  1. Use MySQL's DATE_FORMAT function to format it.
  2. Use MySQL's UNIX_TIMESTAMP function to get a timestamp PHP's date() function can play with.
  3. Run the MySQL DATETIME through PHP's strtotime() function to get a timestamp PHP's date() function can play with.

以#3 为例:

print date('<format string>', strtotime($row['date_added']));

只需按照 date() 上的文档构建您喜欢的格式字符串并将其交换.

Just follow the documentation on date() to construct a format string to your liking and swap it in.

这篇关于打印后使用 PHP 格式化 DATETIME 列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆