- Ada
- C
- Clojure
- Cobol
- C#
- D
- Dart
- Elixir
- Erlang
- Fortran
- Go
- Haskell
- JS
- JS
- Java
- Java
- Java
- Lisp
- Lua
- Obj-C
- PHP
- Pascal
- Perl
- Perl
- Perl
- Python
- Ruby
- Rust
- Rust
- VB
(def d #(java.util.Date.))
Put the _. after java.util.Date in order to get an instance and not read it as a class. Need to declare d with an anonymous function _#() because the date can't be cast to Interface Function.
var d = Date.now();
This returns the number of milliseconds since epoch (not an object).
See the documentation for support and polyfills for non-modern browsers.
See the documentation for support and polyfills for non-modern browsers.
long a = currentTimeMillis();
String d = "%tc".formatted(a);
Date a = getInstance().getTime();
String d = "%tc".formatted(a);
(defparameter d
(multiple-value-bind (seconds minutes hours day month year day-of-the-week daylight-savings-time-p time-zone)
(get-decoded-time)
(declare (ignorable day-of-the-week daylight-savings-time-p time-zone))
(format nil "~D-~2,'0D-~2,'0D ~2,'0D:~2,'0D:~2,'0D~%" year month day hours minutes seconds))
"The current date and time as a string value.")
GET-DECODED-TIME returns 9 values. We capture them all in MULTIPLE-VALUE-BIND. I chose to ignore day-of-the-week , daylight-savings-time-p , and time-zone , but they are still bound.
Note that Lisp's FORMAT specifier string is very different from most other languages!
Note that Lisp's FORMAT specifier string is very different from most other languages!
$d = time;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($d);
Builtin function time gets the number of seconds since epoch. localtime converts to date and time components and returns them as a list. For an OO interface, see Time::Piece.
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
Importing CPAN module Time::Piece replaces perl builtin functions localtime and gmtime with object-oriented equivalents.
programming-idioms.org