Ether
Ether的單位關(guān)鍵字有wei, finney, szabo, ether道宅,換算格式如下:
- 1 ether = 1 * 10^18 wei
- 1 ether = 1 * 10^6 szabo
- 1 ether = 1* 10^3 finney
示例:
pragma solidity 0.4.20;
/**
* 對(duì) 比特幣 Ether 的幾個(gè)單位進(jìn)行測試
*/
contract testEther {
// 定義全局變量
uint public balance;
function testEther() public{
balance = 1 ether; //1000000000000000000
}
function fFinney() public{
balance = 1 finney; //1000000000000000
}
function fSzabo() public{
balance = 1 szabo; //1000000000000
}
function fWei() public{
balance = 1 wei; //1
}
}
Time
Time的單位關(guān)鍵字有seconds, minutes, hours, days, weeks, years,換算格式如下:
- 1 == 1 seconds
- 1 minutes == 60 seconds
- 1 hours == 60 minutes
- 1 days == 24 hours
- 1 weeks == 7 days
- 1 years == 365 days
如果你需要進(jìn)行使用這些單位進(jìn)行日期計(jì)算瓦呼,需要特別小心湾揽,因?yàn)椴皇敲磕甓际?65天苦酱,且并不是每天都有24小時(shí)酥泞,因?yàn)檫€有閏秒伍宦。由于無法預(yù)測閏秒芽死,必須由外部的oracle來更新從而得到一個(gè)精確的日歷庫(內(nèi)部實(shí)現(xiàn)一個(gè)日期庫也是消耗gas的)。
示例:
pragma solidity 0.4.20;
/**
* 對(duì) Time 單位進(jìn)行測試
*/
contract testTime {
// 定義全局變量
uint time;
function testTime() public{
time = 100000000;
}
function fSeconds() public view returns(uint){
return time + 1 seconds; //100000001
}
function fMinutes() public view returns(uint){
return time + 1 minutes; //100000060
}
function fHours() public view returns(uint){
return time + 1 hours; //100003600
}
function fWeeks() public view returns(uint){
return time + 1 weeks; //100604800
}
function fYears() public view returns(uint){
return time + 1 years; //131536000
}
}
在Browser-solidity中調(diào)試:
Time