Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #61 Get current date

Assign to the variable d the current date/time value, in the most standard type.

var d = DateTime.now();
with Ada.Calendar;
D : Ada.Calendar.Time := Ada.Calendar.Clock;
#include <time.h>
time_t d=time(0);
(def d #(java.util.Date.))
IDENTIFICATION DIVISION.
PROGRAM-ID. date.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 curr-date.
   03 year      pic 9(4).
   03 month     pic 9(2).
   03 day       pic 9(2).
PROCEDURE DIVISION.
   MOVE FUNCTION CURRENT-DATE TO curr-date
STOP RUN.
#include <ctime>
std::time_t d = std::time(nullptr);
DateTime d = DateTime.Now;
import std.datetime;
auto d = Clock.currTime;
d = :calendar.local_time
D = calendar:local_time().
integer, dimension(8) :: d

call date_and_time (values=d)

import "time"
d := time.Now()
d <- System.Posix.Time.epochTime
var d = Date.now();
var d = new Date();
long d = System.currentTimeMillis();
long unixEpoch = System.currentTimeMillis();
String d = String.format("%1$tY-%1$tm-%1$td %1$tI:%1$tM:%1$tS", unixEpoch);
import java.time.Instant;
Instant d = Instant.now();
d = os.date()
@import Foundation;
NSDate *d=NSDate.date;
$d = time();
var
  _d: TDateTime;
begin
  _d := Now;
end.
$d = time;

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($d);
use Time::Piece;

$d = localtime;		# local time as a Time::Piece object
say $d->ymd;		# yyyy-mm-dd format
say $d->datetime;	# ISO 8601 format

$g = gmtime;		# GMT as a Time::Piece object
$d = time;
import datetime
d = datetime.datetime.now()
d = Time.now
use std::time::SystemTime;
let d = SystemTime::now();
extern crate time;
let d = time::now();
Dim d As DateTime = DateTime.Now()

New implementation...
< >
programming-idioms.org