Logo

Programming-Idioms

Assign to the string x the value of fields (hours, minutes, seconds) of the date d, in format HH:MM:SS.
Implementation
C#

Implementation edit is for fixing errors and enhancing with metadata. Please do not replace the code below with a different implementation.

Instead of changing the code of the snippet, consider creating another C# implementation.

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
import "time"
x := d.Format("15:04:05")
uses SysUtils;
DefaultFormatSettings.TimeSeparator := ':';
DefaultFormatSettings.ShortTimeFormat := 'hh:mm:ss';
x := TimeToStr(d);
import datetime
d = datetime.datetime.now()
x = d.strftime('%H:%M:%S')
d = Time.now
x = d.strftime("%H:%M:%S")
(define d (current-date))
(define x (substring (date-and-time d) 11 19))

integer, dimension(8) :: d
character (len=8) :: x
call date_and_time (values=d)
write (unit=x,fmt='(I2.2,":",I2.2,":",I2.2)') d(5), d(6), d(7)
const d = new Date();

let hr = d.getHours();
let min = d.getMinutes();
let sec = d.getSeconds();

if ( hr.toString().length === 1 ) {
  hr = '0' + hr;
}

if ( min.toString().length === 1 ) {
  min = '0' + min;
}

if ( sec.toString().length === 1 ) {
  sec = '0' + sec;
}

const x = '' + hr + ':' + min + ':' + sec;
$x = $d->format('H:i:s');
use time::macros::format_description;
let format = format_description!("[hour]:[minute]:[second]");
let x = d.format(&format).expect("Failed to format the time");
with Ada.Calendar.Formatting;
X : constant String :=
    Ada.Calendar.Formatting.Image (D) (12 .. 19);
use DateTime;
$d = DateTime->now; 
$x = $d->hms;
(defvar *x* (format NIL "~2,'0D:~2,'0D:~2,'0D" 12 34 56))