Difference between revisions of "Find the current system time"

From CodeCodex

m
Line 18: Line 18:
 
</pre>
 
</pre>
 
See the Ruby [http://corelib.rubyonrails.org/classes/Time.html API] for functions available to time object.
 
See the Ruby [http://corelib.rubyonrails.org/classes/Time.html API] for functions available to time object.
 +
 +
===Zsh===
 +
<pre>
 +
zmodload zsh/datetime
 +
strftime %c $EPOCHSECONDS
 +
</pre>
  
 
[[Category:Java]]
 
[[Category:Java]]
 
[[Category:Ruby]]
 
[[Category:Ruby]]
 +
[[Category:Zsh]]

Revision as of 17:29, 21 July 2009

Implementations

Java

When you instantiate a GregorianCalendar object in Java, it is created with the current time.

    Calendar cal = new GregorianCalendar();

Then you can use the Calendar object or its methods to get the time information you need.

    // Get the components of the time
    System.out.println( cal.get(Calendar.HOUR_OF_DAY) ); // print the current hour from 0-23
    System.out.println( cal.get(Calendar.MINUTE) );      // print the current minute from 0-59
    System.out.println( cal.get(Calendar.SECOND) );      // print the current second from 0-59

Many more functions are listed in the Java API.

Ruby

time = Time.now

See the Ruby API for functions available to time object.

Zsh

zmodload zsh/datetime
strftime %c $EPOCHSECONDS