Learn Solidity: Ether Units & Time Units in Solidity Programming Language

In this post, we will understand the standard Ether units & time-related units in Solidity Programming Language.

Advertisements
World is looking for a Certified Blockchain Expert Become one

Notice: This is one of the multi-post series of Learn Solidity - Build Decentralized Application in Ethereum. This is an attempt to teach you all about Solidity - A Programming Language for Ethereum Based Smart Contracts. If you want to take this as a video course please signup using below button.
pragma solidity 0.4.8; 

/*
* @title Learn Solidity: Ether Units & Time Units in Solidity Programming Language
* @author Toshendra Sharma
* @notice Example for the Learn Solidity Series
*/

// Solidity define many types of especial units or variables lets check the units here 
// then we will talk about global variables & functions in next lecture

contract Units {
    // Ether Units are available as a global variables
    // wei, finney, szabo & ether are variable themself
    // variable can not be named as the ether, finney, szabo, wei 
    // use http://ether.fund/tool/converter for more such conversion
    bool isEqual = (2 ether == 2000 finney);


    // Time Units are also availabel in solidity like this 
    // seconds, minutes, hours, days, weeks, years are all available at time units to be used
    // can be used anywher in the program like mentioned below
    bool isEqual = (1 == 1 seconds);
    bool isEqual = (1 minutes == 60 seconds);
    bool isEqual = (1 hours == 60 minutes);
    bool isEqual = (1 days == 24 hours);
    bool isEqual = (1 weeks = 7 days);
    bool isEqual = (1 years = 365 days);


    Define consutruct here
    function Units(uint initialCoins) {
       // Initialize state variables here
    }

}
Previous: General Data Types in Solidity? Next: Globally Available Variables & Functions