国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數(shù)據(jù)庫 > MySQL > 正文

MySQL 獲得當(dāng)前日期時間的函數(shù)小結(jié)

2024-07-24 12:49:26
字體:
供稿:網(wǎng)友
1.1 獲得當(dāng)前日期+時間(date + time)函數(shù):now()

mysql> select now();

+---------------------+
| now() |
+---------------------+
| 2008-08-08 22:20:46 |
+---------------------+
除了 now() 函數(shù)能獲得當(dāng)前的日期時間外,MySQL 中還有下面的函數(shù):

current_timestamp()
,current_timestamp
,localtime()
,localtime
,localtimestamp -- (v4.0.6)
,localtimestamp() -- (v4.0.6)
這些日期時間函數(shù),都等同于 now()。鑒于 now() 函數(shù)簡短易記,建議總是使用 now() 來替代上面列出的函數(shù)。

1.2 獲得當(dāng)前日期+時間(date + time)函數(shù):sysdate()

sysdate() 日期時間函數(shù)跟 now() 類似,不同之處在于:now() 在執(zhí)行開始時值就得到了, sysdate() 在函數(shù)執(zhí)行時動態(tài)得到值。看下面的例子就明白了:

mysql> select now(), sleep(3), now();

+---------------------+----------+---------------------+
| now() | sleep(3) | now() |
+---------------------+----------+---------------------+
| 2008-08-08 22:28:21 | 0 | 2008-08-08 22:28:21 |
+---------------------+----------+---------------------+mysql> select sysdate(), sleep(3), sysdate();

+---------------------+----------+---------------------+
| sysdate() | sleep(3) | sysdate() |
+---------------------+----------+---------------------+
| 2008-08-08 22:28:41 | 0 | 2008-08-08 22:28:44 |
+---------------------+----------+---------------------+
可以看到,雖然中途 sleep 3 秒,但 now() 函數(shù)兩次的時間值是相同的; sysdate() 函數(shù)兩次得到的時間值相差 3 秒。MySQL Manual 中是這樣描述 sysdate() 的:Return the time at which the function executes。

sysdate() 日期時間函數(shù),一般情況下很少用到。

2. 獲得當(dāng)前日期(date)函數(shù):curdate()

mysql> select curdate();

+------------+
| curdate() |
+------------+
| 2008-08-08 |
+------------+
其中,下面的兩個日期函數(shù)等同于 curdate():

current_date()
,current_date
3. 獲得當(dāng)前時間(time)函數(shù):curtime()

mysql> select curtime();

+-----------+
| curtime() |
+-----------+
| 22:41:30 |
+-----------+
其中,下面的兩個時間函數(shù)等同于 curtime():

current_time()
,current_time
4. 獲得當(dāng)前 UTC 日期時間函數(shù):utc_date(), utc_time(), utc_timestamp()

mysql> select utc_timestamp(), utc_date(), utc_time(), now()

+---------------------+------------+------------+---------------------+
| utc_timestamp() | utc_date() | utc_time() | now() |
+---------------------+------------+------------+---------------------+
| 2008-08-08 14:47:11 | 2008-08-08 | 14:47:11 | 2008-08-08 22:47:11 |
+---------------------+------------+------------+---------------------+
因為我國位于東八時區(qū),所以本地時間 = UTC 時間 + 8 小時。UTC 時間在業(yè)務(wù)涉及多個國家和地區(qū)的時候,非常有用。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 夹江县| 汶川县| 林周县| 泾阳县| 新源县| 攀枝花市| 石景山区| 紫金县| 长宁区| 伊宁县| 牡丹江市| 沾化县| 毕节市| 长寿区| 丹棱县| 璧山县| 林州市| 临颍县| 平湖市| 新和县| 武鸣县| 巩义市| 富阳市| 庄浪县| 天峻县| 崇阳县| 集贤县| 波密县| 永嘉县| 大邑县| 班戈县| 西和县| 鞍山市| 蓬安县| 边坝县| 莱西市| 安新县| 淮阳县| 乌兰县| 颍上县| 台东县|