Convert PHP code into Ruby!
RSS icon Email icon Home icon
  • time

    Posted on May 20th, 2009 RubyLove No comments

    Returns the current Unix timestamp (epoch).

    PHP

    echo time();
    // => 1242744141

    Ruby

    puts Time.now.to_i;
    # => 1242744141
  • microtime

    Posted on May 17th, 2009 RubyLove 1 comment

    Returns the current Unix timestamp (epoch) with microseconds.

    PHP

    echo microtime();
    // => 0.63928794 1242744141

    Ruby

    epoch_mirco = Time.now.to_f;
    epoch_full = Time.now.to_i;
     
    epoch_fraction = epoch_mirco - epoch_full;
     
    puts epoch_fraction.to_s + ' ' + epoch_full.to_s;
    # => 0.639287948608398 1242744141