MySQL 获取系统时间/系统日期/日期时间的函数

您所在的位置:网站首页 获取电脑当前时间 MySQL 获取系统时间/系统日期/日期时间的函数

MySQL 获取系统时间/系统日期/日期时间的函数

#MySQL 获取系统时间/系统日期/日期时间的函数| 来源: 网络整理| 查看: 265

文章目录 一、获取当前系统日期和时间(一)now(),返回当前的系统日期和时间(二)sysdate(),返回当前的系统日期和时间(三)current_timestamp(),返回当前的系统日期和时间(四)localtime(),返回当前的系统日期和时间 二、获取当前的系统日期(一)curdate(),返回当前的系统日期(二)current_date(),返回当前的系统日期(三)current_date,返回当前的系统日期 三、获取当前的系统时间(一)curtime(),返回当前的系统时间(二)current_time(),返回当前的系统时间(三)current_time,返回当前的系统时间 四、获取 UTC 时间(一)utc_date(),获取 UTC 日期(二)utc_time(),获取 UTC 时间(三)utc_timestamp(),获取 UTC 的日期和时间 五、日期和时间显示格式说明

一、获取当前系统日期和时间 (一)now(),返回当前的系统日期和时间

now() 函数以 YYYY-MM-DD HH:MM:SS 返回系统当前的日期时间,可以直接存到 DATETIME 字段中。下面的 sysdate() 函数也是如此。

mysql> select now(); +---------------------+ | now() | +---------------------+ | 2021-06-04 08:24:51 | +---------------------+ 1 row in set (0.00 sec) (二)sysdate(),返回当前的系统日期和时间 mysql> select sysdate(); +---------------------+ | sysdate() | +---------------------+ | 2021-06-04 08:27:35 | +---------------------+ 1 row in set (0.00 sec)

now() 和 sysdate() 这两个函数都是获取当前日期+时间,不同之处在于:now() 在执行开始时值就得到了,sysdate() 在函数执行时动态得到值。

(三)current_timestamp(),返回当前的系统日期和时间 mysql> select current_timestamp(); +---------------------+ | current_timestamp() | +---------------------+ | 2021-06-04 14:12:37 | +---------------------+ 1 row in set (0.00 sec) (四)localtime(),返回当前的系统日期和时间 mysql> select localtime(); +---------------------+ | localtime() | +---------------------+ | 2021-06-04 14:13:54 | +---------------------+ 1 row in set (0.00 sec) 二、获取当前的系统日期 (一)curdate(),返回当前的系统日期

curdate() 以 YYYY-MM-DD 的格式返回今天的日期,可以直接存到 DATE 字段中。下面函数两个也是如此。

mysql> select curdate(); +------------+ | curdate() | +------------+ | 2021-06-04 | +------------+ 1 row in set (0.00 sec) (二)current_date(),返回当前的系统日期 mysql> select current_date(); +----------------+ | current_date() | +----------------+ | 2021-06-04 | +----------------+ 1 row in set (0.00 sec) (三)current_date,返回当前的系统日期 mysql> select current_date; +--------------+ | current_date | +--------------+ | 2021-06-04 | +--------------+ 1 row in set (0.00 sec) 三、获取当前的系统时间 (一)curtime(),返回当前的系统时间

curtime() 以 HH:MM:SS 的格式返回当前的时间,可以直接存到 TIME 字段中。以下两个函数也是如此。 举例如下:

mysql> select curtime(); +-----------+ | curtime() | +-----------+ | 10:55:13 | +-----------+ 1 row in set (0.03 sec) (二)current_time(),返回当前的系统时间 (三)current_time,返回当前的系统时间 四、获取 UTC 时间

协调世界时,又称世界统一时间,世界标准时间,国际协调时间,简称 UTC。

(一)utc_date(),获取 UTC 日期 mysql> select utc_date(); +------------+ | utc_date() | +------------+ | 2021-06-04 | +------------+ 1 row in set (0.15 sec) (二)utc_time(),获取 UTC 时间 mysql> select utc_time(); +------------+ | utc_time() | +------------+ | 06:47:26 | +------------+ 1 row in set (0.00 sec) (三)utc_timestamp(),获取 UTC 的日期和时间 mysql> select utc_timestamp(); +---------------------+ | utc_timestamp() | +---------------------+ | 2021-06-04 07:04:35 | +---------------------+ 1 row in set (0.00 sec) 五、日期和时间显示格式说明 编程狮(w3cschool.cn)  值含义秒%S、%s两位数字形式的秒( 00,01, ..., 59)分%I、%i两位数字形式的分( 00,01, ..., 59)小时 %H24小时制,两位数形式小时(00,01, ...,23)%h12小时制,两位数形式小时(00,01, ...,12)%k24小时制,数形式小时(0,1, ...,23)%l12小时制,数形式小时(0,1, ...,12)%T24小时制,时间形式(HH:mm:ss)%r 12小时制,时间形式(hh:mm:ss AM 或 PM)%p AM上午或PM下午   周  %W一周中每一天的名称(Sunday,Monday, ...,Saturday) %a一周中每一天名称的缩写(Sun,Mon, ...,Sat) %w 以数字形式标识周(0=Sunday,1=Monday, ...,6=Saturday) %U数字表示周数,星期天为周中第一天%u数字表示周数,星期一为周中第一天天%d 两位数字表示月中天数(01,02, ...,31)%e  数字表示月中天数(1,2, ...,31) %D英文后缀表示月中天数(1st,2nd,3rd ...)  %j以三位数字表示年中天数(001,002, ...,366) 月%M 英文月名(January,February, ...,December) %b 英文缩写月名(Jan,Feb, ...,Dec) %m 两位数字表示月份(01,02, ...,12)%c 数字表示月份(1,2, ...,12) 年%Y 四位数字表示的年份(2015,2016...)%y  两位数字表示的年份(15,16...)文字输出 %文字 直接输出文字内容


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3