View Subcategory

Display the current date and time

Create a Date object representing the current date and time. Print it out.
If you can also do this without creating a Date object you can show that too.
ruby
puts DateTime.now
java
import java.util.Date;

public class SolutionXX {
public static void main(String[] args) {
Date now = new Date();
System.out.println(now.toString());
}
}
perl
use Class::Date;
my $date = Class::Date->now();
print $date->string()."\n";

print localtime()."\n";
use Time::Piece ();

# Date object
my $date = Time::Piece::localtime;
print "$date\n";
# no object
print scalar(localtime),"\n";
groovy
println new Date()
scala
println(new java.util.Date)
python
from datetime import datetime
print datetime.utcnow()
cpp
QDate now = QDate::currentData();
qDebug() << now.toString();
time_t date = time(0);
cout << ctime(&date);
fsharp
printfn "%A" System.DateTime.Now
erlang
io:format("~p~n", [calendar:local_time()])
ocaml
Unix.localtime (Unix.gettimeofday ())
csharp
// Creating a variable first:
DateTime now = DateTime.Now;
Console.WriteLine(now);

// Without creating a variable:
Console.WriteLine(DateTime.Now);
php
echo date('r') . "\n";
$d = new DateTime();
echo $d->format('r') . "\n";
haskell
import System.Time

main = do ct <- getClockTime
print ct
import Data.Time

main = do zt <- getZonedTime
print zt
import System.Time

main = print =<< getClockTime
clojure
(import 'java.util.Date)

(println (str (Date.)))
(prn (java.util.Date.))
fantom
echo(DateTime.now)
go
fmt.Println(time.Now())