> For the complete documentation index, see [llms.txt](https://chihaolu.gitbook.io/all-in-one-solidity/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://chihaolu.gitbook.io/all-in-one-solidity/part-i-basic/chapter-3-dan-wei-unit-yun-suan-zi-operators/time.md).

# 【Time】

Solidity 還提供時間的語法，只是跟我們平常熟知的表示形式不同，Solidity 內表示時間的方式是 [UNIX 時間 (Unix time)](https://www.unixtimestamp.com/)。

所謂的 UNIX 時間是從 UTC 1970 年 1 月 1 日 0 時 0 分 0 秒起至現在的總秒數，不考慮閏秒。

```solidity
pragma solidity ^0.8.11;

contract MyTime {
    // 1 == 1 seconds
    // 1 minutes == 60 seconds
    // 1 hours == 60 minutes
    // 1 days == 24 hours
    // 1 weeks == 7 days
    uint256 public levelUpRate = 1 days; // 回傳秒
    uint public constant FIRST_MINTING_DATE = 1640995200;
    // uint time = now;
}
```

其中在 Solidity 0.7.0 之前我們還可以使用語法 `now` 得到當前的時間，而 `now` 與 我們會來會提到的 `block.timestamp` 是一樣的，因為 `now` 代表的就是當前的 block timestamp。

由於當前版本已經超過 0.7.0，所以要表示當前時間只能使用 `block.timestamp`。至於什麼是 block timestamp 之後在全局變量的地方會介紹。
