solidity获取时间戳
时间: 2024-04-24 08:17:11 浏览: 211
Solidity Documentation
以下是两种Solidity获取时间戳的方法:
1.使用now关键字获取当前块的时间戳
```solidity
pragma solidity >=0.4.22 <0.6.0;
contract MyContract {
uint public timestamp;
function getTimestamp() public {
timestamp = now;
}
}
```
2.在函数中使用block.timestamp获取当前块的时间戳
```solidity
pragma solidity >=0.4.22 <0.6.0;
contract MyContract {
uint public timestamp;
function getTimestamp() public {
timestamp = block.timestamp;
}
}
```
阅读全文