> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# now, current_timestamp, localtime, localtimestamp

> 返回当前日期和时间，支持指定秒精度。

获取当前的时间，以 DATETIME 类型返回。

从 3.1.6 版本开始，now() 函数支持接收精度参数 `p`，代表秒之后保留的精度位数，最多保留 6 位，即最高精确到微秒（microsecond）。`p` 位之后不足 6 位的使用 0 填充。如果不指定 `p`，仍然返回秒级精度的时间。

指定 0-6 位的秒精度，返回不同精度的时间。

```plaintext theme={null}
mysql > select now(),now(1),now(2),now(3),now(4),now(5),now(6)\G
*************************** 1. row ***************************
 now(): 2023-12-08 13:46:45
now(1): 2023-12-08 13:46:45.100000
now(2): 2023-12-08 13:46:45.110000
now(3): 2023-12-08 13:46:45.115000
now(4): 2023-12-08 13:46:45.115800
now(5): 2023-12-08 13:46:45.115840
now(6): 2023-12-08 13:46:45.115843
```

该函数受时区影响，具体参见 [设置时区](/documents/cn/4.2/administration/management/timezone.md)。

## 语法

```Haskell theme={null}
DATETIME NOW()
DATETIME NOW(INT p)
```

## 参数说明

`p`：可选，指定的时间精度位数，支持的数据类型为 INT。最大支持返回微秒级时间（最多 6 位）。`select now(0)` 等同于 `select now()`。

## 返回值说明

* 如果不指定 `p`，则返回秒级精度的时间。
* 如果指定了 `p`，则返回指定精度的时间。

## 示例

```Plain Text theme={null}
-- 返回当前的时间。
select now();
+---------------------+
| now()               |
+---------------------+
| 2022-10-09 21:19:35 |
+---------------------+

-- 返回指定精度的时间。
mysql > select now(),now(1),now(2),now(3),now(4),now(5),now(6)\G
*************************** 1. row ***************************
 now(): 2023-12-08 13:46:45
now(1): 2023-12-08 13:46:45.100000
now(2): 2023-12-08 13:46:45.110000
now(3): 2023-12-08 13:46:45.115000
now(4): 2023-12-08 13:46:45.115800
now(5): 2023-12-08 13:46:45.115840
now(6): 2023-12-08 13:46:45.115843
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.