New answers tagged

0

VBA, 27 bytes This program adds an approximation of 1000 years, in days, to the current time, and instructs the program to wait until that time is encountered. Application.Wait 365242+Now For for a more accurate result, the below may be used at a cost of 41 bytes. Application.Wait DateAdd("yyyy",1000,Now)


2

Rust, 55 bytes ||std::thread::sleep(std::time::Duration::new(2<<34,0)) Try it online! (or not, it will take ~1089 years to do anything interesting) Rust's thread::sleep takes a Duration as an input, and those conveniently store the count of seconds as a u64.


1

CJam, 15 14 bytes -1 byte because I forgot that e[numeric literal] existed. es3e13+{_es>}g Please don't try it online, it won't work! This waits in a while loop until the current Unix timestamp is equal to the timestamp at the beginning of execution plus 3*10^13 milliseconds (or ~951.3 years).


2

Matlab, 12 bytes pause(3e+10) This will sleep for 951 years which is within 10% of 1000 years. Note that Matlab can sleep for a floating number of seconds. This is my first ever answer on CodeGolf :)


2

Groovy, 63 bytes f={s,n->sprintf('%tFT%1$tT.%06d',s*1000L,n/1E3as int)-~/\.0+$/} Try it online! A different Groovy approach using format strings (inspired by other similar answers).


1

Python 3, 68 bytes import time t=time.gmtime() print('%03d'%(-~t[3]%24/.024+t[4]/1.44)) Try it online!


1

Raku, 46 bytes 40 chars, 42 bytes {(~DateTime.new($^a+$^b divⅯ/1e6)).chop} Try it online! Saved a few bytes by using a non-digit numeral (which could be replaced by others like ൲, but others like 𐄢 or 𑁥 add an extra byte), which allowed the space removed after div. Only trick here was needing to force the round down, and stringify the DateTime to be ...


1

Excel, 102 101 bytes =TEXT(25569+A1/86400,"yyy-mm-ddThh:mm:ss")&SUBSTITUTE(LEFT(TEXT(B1/10^9,"."&REPT(0,9)),7),".000000",) Input is seconds in A1 and nanoseconds in B1. There are two major pieces to this: TEXT(25569+A1/86400,"yyy-mm-ddThh:mm:ss") 25569 is the numerical equivalent of 1970-01-01 in Excel which ...


1

Japt, 27 23 19 15 bytes Kj z86400 s t3n Test it Javascript port. I hope I've done it correctly. -4 bytes from Shaggy. -4 more bytes from Shaggy. -4 more more bytes from Shaggy.


3

Japt, 32 28 bytes Takes input as a pair of strings, with the nanoseconds first. Can save (at least) 4 bytes if we can include leading 0s with the nanoseconds. ùT9 ¯6 pU=n g)iÐV*A³ s3 ¯UÄ9 Try it Or, to "translate" that to JavaScript: U=>V=>( U=U.padStart(9,0).slice(0,6), U.repeat(U=Math.sign(parseInt(U))).replace(/^/,new Date(V*10**3)...


1

APL (Dyalog Unicode) 18.0, 53 bytes (SBCS) Full program. Prompts for nanoseconds, then seconds. (¯7×0=f)↓⊃'%ISO%.ffffff'(1200⌶)20 1⎕DT⎕+1E¯6×f←⌊⎕÷1E3 Try it online! (polyfills for ⌶ and ⎕DT because TIO still uses 17.1) ⎕÷1E3 divide input nanoseconds by 1000 f← assign to f 1E¯6× multiply by 0.000001 ⎕+ add input seconds to that 20 1⎕DT convert from UNIX ...


2

Groovy, 62 60 68 bytes f={s,n->"${java.time.Instant.ofEpochSecond(s,n|1)}"[0..25]-~/\.0+$/} Try it online! Explanation The Java ofEpochSecond(epochSecond, nanoAdjustment) method returns the Instant corresponding to the given seconds and nanoseconds (exactly what we want for this challenge). The nanoseconds are bitwise-ORed with 1 to ensure we ...


3

C (gcc), 108 106 bytes Saved 2 bytes thanks to ceilingcat!!! #import<time.h> o[9];f(s,n)long s;{strftime(o,99,"%FT%T",gmtime(&s));printf((n/=1e3)?"%s.%06d":"%s",o,n);} Try it online! Inputs seconds and nanoseconds as integers and outputs the formatted date/time to stdout.


3

Wolfram Language (Mathematica), 91 bytes DateString[6!3068040+#2,"ISODateTime"]<>If[#>999,"."<>IntegerString[⌊#/1000⌋,10,6],""]& Try it online! Mathematica supports milliseconds, but not microseconds.


1

JavaScript (V8), 83 94 ... 78 bytes s=>n=>new Date(s*1e3).toJSON(n=0|n/1e3).slice(0,20-!n)+`${n+1e6}`.slice(n?1:7) Try it online! Thanks to @Neil for the great help! Saved another 5 thanks to @Arnauld


3

Perl 5 (-p -MPOSIX+strftime -Minteger), 55, 51, 60 bytes Thanks to @Abigail for giving me the idea to change the input format. + 9 bytes to handle the microseconds=0 case. $_=(strftime"%FT%T",gmtime$_).sprintf".%06d",<>/1e3 $_=(strftime"%FT%T",gmtime$_).sprintf".%06d",<>/1e3;s;\.0+$; Try it online!


5

Bash + sed, 37, 59, 50 bytes printf '%(%FT%T)T.%06d' $1 $[$2/1000] printf "%(%FT%T)T.%06d" $1 ${2::-3}|sed s/\\.0*$// Try it online! 8 bytes saved thanks to @DigitalTrauma


1

Python 3.8 (pre-release) 106, 81 bytes lambda a,b:datetime.fromtimestamp(a+b//1e3/1e6).isoformat() from datetime import* Try it online!


1

Japt, 9 bytes Ð864e7+Kj Test it My first Japt answer! A port of the existing JS answer.


1

Japt -x, 20 bytes 366õÈ=ÐUTX)f j «3aXe Try it


1

APL (Dyalog Extended), 39 bytes {+/1⍭2⊃¨¯1⎕DT{⍵/⍨3=7|⍵}⊃↓∘⍳/1⎕DT,¨⍵+⍳2} Try it online! Just that much away from MATL. ∆DT is polyfilled in this answer because it isn't available on tio. It was created by Adám(I simply cannot thank him enough for his help). Explanation {+/1⍭2⊃¨¯1⎕DT{⍵/⍨3=7|⍵}⊃↓∘⍳/1⎕DT,¨⍵+⍳2} ⍵+⍳2 year and ...


Top 50 recent answers are included