...by Daniel Szego
quote
"Simplicity is the ultimate sophistication."
Leonardo da Vinci

Saturday, January 13, 2018

Solidity and Truffle Tips and Tricks - time in solidity


Time in solidity does not have too many options unfortunately, what you can use is basically an uint variable that represents a UNIX timestamp, that is basically the number of ticks or seconds since the 1th of January 1970. You can have the keywords now to represent the current timestamp and use the keywords like seconds, minutes, hours, days, weeks or years to add or subtract time elements. As it is demonstrated in the following code fragment:

    uint currentTime = now;
    uint nextSecond = currentTime + 1 seconds;
    uint nextMinute = currentTime + 1 minutes;
    uint nextHour = currentTime + 1 hours;
    uint nextDay = currentTime + 1 days;
    uint nextWeek = currentTime + 1 weeks;
    uint nextYear = currentTime + 1 years;