You are given an integer n as input, and, regardless of the current date, must return the calendar year (Gregorian calendar, other calendars not allowed) taking place n seconds from now.
Rules
- You may not assume that the current year is 2021. In other words, imagine a user testing your solution in five years.
- Standard loopholes forbidden.
- Shortest answer in bytes wins.
- Built-in date functions are allowed.
- You must also support negative numbers.
- On the topic of the year zero: Your answer must follow the ISO specifications, meaning there is a year zero.
- You may assume that the input is always an integer within bounds of your language number system.
- If your language's date functions take leap seconds into account, then follow your language, otherwise do not take leap seconds into account.
Examples (in this case, measured at the time of writing, which is February 15, 2021)
100000000000 -> 5190
1000 -> 2021
54398643 -> 2022
54398643234 -> 3744
-100000000000 -> -1148
38 Answers 38
Ohm v2, 5 bytes
υ!+υy
Explanation:
υ!+υy
υ! get the current timestamp in seconds
+ sum with the implicit input
υy get the year from the resulting timestamp
-
2\$\begingroup\$ υ is a two byte unicode charicter, so this is 7 bytes. "echo 'υ!+υy' | wc -c" returns 8 including the newline character. \$\endgroup\$timthelion– timthelion2021年02月16日 17:07:10 +00:00Commented Feb 16, 2021 at 17:07
-
6\$\begingroup\$ @timthelion Ohm use a custom code-page as many other languages do, you can read more about it here codegolf.meta.stackexchange.com/a/10187/72733 \$\endgroup\$Cinaski– Cinaski2021年02月16日 17:29:49 +00:00Commented Feb 16, 2021 at 17:29
-
1\$\begingroup\$ Wow, haven't seen this language used in a long time! This kind of challenge is exactly what I added the time builtins for, very nice solution! \$\endgroup\$Nick Clifford– Nick Clifford2021年02月17日 15:39:20 +00:00Commented Feb 17, 2021 at 15:39
-
7\$\begingroup\$ Why not
date -d1ドルsec +%Y? Try it online! \$\endgroup\$manatwork– manatwork2021年02月15日 15:55:16 +00:00Commented Feb 15, 2021 at 15:55 -
\$\begingroup\$ Sorry, disregard my comment, forgot it's
nseconds and not 1 second. \$\endgroup\$user344– user3442021年02月17日 14:41:47 +00:00Commented Feb 17, 2021 at 14:41
-
\$\begingroup\$ Oh my, of course! (deletes his own answer in shame) \$\endgroup\$Kaddath– Kaddath2021年02月15日 14:36:54 +00:00Commented Feb 15, 2021 at 14:36
-
4
-
1\$\begingroup\$ @640KB Nice! It's been a while since I did PHP. Back when I stopped, the Arrow Function RFC was still open. Glad to see it being part of the language now. \$\endgroup\$oktupol– oktupol2021年02月15日 18:37:49 +00:00Commented Feb 15, 2021 at 18:37
-
\$\begingroup\$ @oktupol yeah but they have strange limitations, such as you cannot do loops in them, or use recursion (without lengthy tricks) \$\endgroup\$Kaddath– Kaddath2021年02月16日 08:25:03 +00:00Commented Feb 16, 2021 at 8:25
-
\$\begingroup\$
<?=date(Y,time()+$argn);for 24? What's the current consent for $argn? +2 for the flag? \$\endgroup\$Christoph– Christoph2021年02月16日 09:05:32 +00:00Commented Feb 16, 2021 at 9:05
05AB1E, 116 bytes
"`т‰0Kθ4ÖUD2Qi28円X+ë<7%É31α}"Vžežfžg)IŽa+·÷ÄF©IdiY.V‹i®¬>0ë®13⁄4ǝDÅsD12‹i>1ë1円Dǝ¤>2}}ǝëć©ić©i<D_-12š31šë®<šDY.Všë®<š]θ
Here we go again..
Try it online or try it only with custom specified starting date. (Pretty slow for large inputs, so won't be able to output the larger test cases with the current date.)
Explanation:
Since 05AB1E doesn't have any date builtins (except for the current day/time), I've calculated things manually before. I've used the code of going to the next day from this answer of mine, which in turns also uses the leap year calculation of this answer of mine.
Since this challenge also asks to go back in time, I've modified the program accordingly to support that as well.
Step 1: Create a function to calculate the amount of days in a month for a given year/month:
"`т‰0Kθ4ÖUD2Qi28円X+ë<7%É31α}" # Push this string
V # Pop and store it in variable `Y`
` # Pop the list and push all values separated to the stack
# (the year will be at the top; month below it)
т‰ # Take the divmod-100 of the year
0K # Remove the 0s
θ # Pop and push its last item
4Ö # Check if it's divisible by 4
U # Pop and store this in variable `X`
# (X=1 for leap years; X=0 for non-leap years)
D # Duplicate the current month
2Qi # If it's equal to 2 (thus February):
\ # Discard the duplicated month
28X+ # Push 28 + isLeapYear from variable `X`
ë # Else:
< # Decrease the month by 1
7% # Modulo-7
É # Modulo-2
31α # Absolute difference with 31
} # Close the if-else statement
Step 2: Now we determine the current date, and loop an amount of times depending on the input:
že # Push the current day
žf # Push the current month
žg # Push the current year
) # Wrap all three into a list
I # Push the input-integer
Ža+ # Push compressed integer 42300
· # Double it to 84600 (60*60*24)
÷ # Integer-divide the input by 84600
Ä # Take its absolute value
F # And loop that many times:
Step 3: If the input was positive, calculate the next date:
© # Store the current date in variable `®` (without popping)
Idi # If the input is non-negative:
Y.V # Execute string `Y` as 05AB1E code to get the amount
# of days for the current month/year
‹i # If this is smaller than the current days:
® # Push the current date again
¬ # Get its first item (the days)
> # Increase the day by 1
0 # Push index 0
ë # Else:
® # Push the current date again
1 # Push day=1
3⁄4 # Push index 0
ǝ # Insert days=1 at index 0 into the date
D # Duplicate it
Ås # Pop and push its middle item (the month)
D # Duplicate that month
12‹i # If it's smaller than 12:
> # Increase the month by 1
1 # Push index 1
ë # Else:
\ # Discard the duplicated month
1 # Push month=1
D # Push index 1
ǝ # Insert month=1 at index 1 into the date
¤ # Push its last item (the year)
> # Increase the year by 1
2 # Push index 2
} # Close the if-else statement
} # Close the if-else statement
ǝ # Insert the value at the given index into the date
Step 4: If the input was negative instead, calculate the previous date:
ë # Else (the input is negative):
ć # Extract head; push [month,year] and day separated
© # Store the day in variable `®` (without popping)
i # If day == 1:
ć # Extract head; push [year] and month separated
© # Store the month in variable `®` (without popping)
i # If month == 1:
< # Decrease the [year] by 1
D # Duplicate it
_ # Check if it's equal to 0 (1 if 0; 0 otherwise)
- # Subtract that (so we go from year 1 to -1)
12š31š # Prepend 12 and 31: [31,12,year-1-(year-1==0)]
ë # Else:
®<š # Prepend month-1 to the [year] list
D # Duplicate it
Y.V # Execute string `Y` as 05AB1E code to get the amount
# of days for this month/year
š # Prepend this to the [month-1,year] list
ë # Else:
®<š # Prepend day-1 to the [month,year] list
Step 5: After the loop, extract the year to output:
] # Close both the if-else and loop
θ # Pop the date, and only leave its last item (the year)
# (after which it is output implicitly as result)
See this 05AB1E tips of mine (section How to compress large integers?) to understand why Ža+ is 42300.
-
3\$\begingroup\$ Oh my. Debugging this must have been fun :-) \$\endgroup\$Luis Mendo– Luis Mendo2021年02月15日 16:08:00 +00:00Commented Feb 15, 2021 at 16:08
-
\$\begingroup\$ @LuisMendo Haha, most of it has been done before in other challenges. But I indeed debugged going to the previous date, since that is new. :) \$\endgroup\$Kevin Cruijssen– Kevin Cruijssen2021年02月15日 16:09:03 +00:00Commented Feb 15, 2021 at 16:09
-
3\$\begingroup\$ Nice, extremely creative. This must have taken a while to write \$\endgroup\$user100690– user1006902021年02月15日 16:09:07 +00:00Commented Feb 15, 2021 at 16:09
-
5\$\begingroup\$ @expressjs123 Probably longer than most of the answers indeed. 05AB1E is a code-golf language, so in most challenges one of the shortest. With date-related challenges on the other hand, it's usually one of the longest, since it has to do almost everything manually. But I kinda like doing those kind of challenges in 05AB1E regardless. ;) \$\endgroup\$Kevin Cruijssen– Kevin Cruijssen2021年02月15日 16:16:18 +00:00Commented Feb 15, 2021 at 16:16
-
3\$\begingroup\$ Looks like the tables have turned :P. +1 for doing something like this in a golfing language \$\endgroup\$user– user2021年02月15日 16:26:50 +00:00Commented Feb 15, 2021 at 16:26
Ruby, 21 bytes
->n{[*Time.now+n][5]}
Shorter by a byte than the more obvious ->n{(Time.now+n).year}.
-
\$\begingroup\$ The shortest answer I can actually understand! (the APL one is shorter but it's harder to make something of it) \$\endgroup\$user100690– user1006902021年02月15日 14:46:52 +00:00Commented Feb 15, 2021 at 14:46
-
\$\begingroup\$ @expressjs123 I've added an explanation. Let me know if I need to expand on anything. \$\endgroup\$Adám– Adám2021年02月15日 16:23:28 +00:00Commented Feb 15, 2021 at 16:23
-
1\$\begingroup\$ Nice. Never even thought about decomposing a
Timeobject. \$\endgroup\$engineersmnky– engineersmnky2021年02月17日 03:00:17 +00:00Commented Feb 17, 2021 at 3:00
Octave / MATLAB, 27 bytes
@(x)datestr(x/86400+now,10)
How it works
@(x) % Define anonymous function with input x
x/86400 % Divide input by 86400, to convert to days
now % Current time in days since "January 0, 0000"
+ % Add
datestr( ,10) % Convert to string with format 10, which is year
-
8\$\begingroup\$ Would the downvoter be so kind to explain how I can improve my answer (other than posting an explanation, which I haven't had the time for yet)? \$\endgroup\$Luis Mendo– Luis Mendo2021年02月15日 16:13:06 +00:00Commented Feb 15, 2021 at 16:13
-
\$\begingroup\$ Many answers here are getting downvoted without explanation :/ \$\endgroup\$Razetime– Razetime2021年02月15日 16:22:17 +00:00Commented Feb 15, 2021 at 16:22
-
1\$\begingroup\$ @Razetime I've seen that happen, sometimes, to answers in golfing languages. Some people don't like those languages and decide that's enough reason to downvote. But Octave? \$\endgroup\$Luis Mendo– Luis Mendo2021年02月15日 17:03:19 +00:00Commented Feb 15, 2021 at 17:03
-
\$\begingroup\$ not a downvote but it's easy to find a failing input since not all days are 86400 seconds long \$\endgroup\$Agos– Agos2021年02月17日 10:06:19 +00:00Commented Feb 17, 2021 at 10:06
-
\$\begingroup\$ @Agos Good point. I have asked the OP if leap seconds need to be taken into account. Doing it would complicate answers a lot \$\endgroup\$Luis Mendo– Luis Mendo2021年02月17日 11:00:57 +00:00Commented Feb 17, 2021 at 11:00
-
\$\begingroup\$ Nice answer, but not accepting it yet (waiting a week to accept any answer) \$\endgroup\$user100690– user1006902021年02月15日 14:00:42 +00:00Commented Feb 15, 2021 at 14:00
-
4\$\begingroup\$ @expressjs123 For code-golf challenges, we usually do not accept any answer. If you really want to accept one, you should indeed wait at least one week before doing so and pick the shortest one (which is not going to be this one). \$\endgroup\$Arnauld– Arnauld2021年02月15日 14:05:19 +00:00Commented Feb 15, 2021 at 14:05
jq, (削除) 20 (削除ここまで) 15 characters
now+.|gmtime[0]
Sample run:
bash-5.0$ jq 'now+.|gmtime[0]' <<< 100000000000
5190
-
\$\begingroup\$ Sorry, I totally misinterpreted the question and missed that it's
nseconds instead of 1 second... \$\endgroup\$user344– user3442021年02月17日 15:12:48 +00:00Commented Feb 17, 2021 at 15:12
PowerShell, (削除) 32 (削除ここまで) (削除) 26 (削除ここまで) 23 bytes
date|% *dds* @args|% y*
-3 bytes thanks to mazzy and ZaelinGoodman
-
2\$\begingroup\$ Darnit, I didn't see that somebody already did Powershell before me! I came to almost the same solution, so here's a few bytes for you from mine! Try it online! \$\endgroup\$Zaelin Goodman– Zaelin Goodman2021年02月15日 19:55:37 +00:00Commented Feb 15, 2021 at 19:55
-
2\$\begingroup\$ so that the array of
argsdoes not confuse anyone Try it online! :) \$\endgroup\$mazzy– mazzy2021年02月15日 20:51:22 +00:00Commented Feb 15, 2021 at 20:51
Python 3, (削除) 74 (削除ここまで) (削除) 72 (削除ここまで) 65 bytes
lambda x:(date.today()+timedelta(0,x)).year
from datetime import*
-7 bytes thanks to @Eric
-
1\$\begingroup\$ According to the rules, you can get rid of the
f=: Try it online! \$\endgroup\$movatica– movatica2021年02月15日 16:39:03 +00:00Commented Feb 15, 2021 at 16:39 -
1\$\begingroup\$ @Movatica thanks!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \$\endgroup\$avarice– avarice2021年02月15日 16:41:28 +00:00Commented Feb 15, 2021 at 16:41
-
2\$\begingroup\$ You need to return a year, not print it. So it's allowed to move
print()to the footer, for 7 fewer bytes. tio.run/##FcrBCoQgEADQe1/hcaYNibSlXehPukyoJGSKzCG/… \$\endgroup\$Eric Duminil– Eric Duminil2021年02月15日 22:24:51 +00:00Commented Feb 15, 2021 at 22:24 -
\$\begingroup\$ @EricDuminil thanks!!! \$\endgroup\$avarice– avarice2021年02月16日 04:22:24 +00:00Commented Feb 16, 2021 at 4:22
Japt, (削除) 12 (削除ここまで) 10 bytes
ÐKj +Ue3)i
-2 bytes from AZTECCO.
This transpiles to the following JS:
new Date(K.j() + U * 1e3).i()
where K.j() is the current time converted to milliseconds, U is the input, and .i() gets the year from the date constructor.
-
1
-
\$\begingroup\$ As Ð is a two byte unicode character, this is actually 11 bytes. \$\endgroup\$timthelion– timthelion2021年02月16日 17:10:12 +00:00Commented Feb 16, 2021 at 17:10
-
1\$\begingroup\$ @timthelion Japt has a custom codepage, just like the 05AB1E answer and Ohm answers do. Click on the "bytes" link to see its encoding. \$\endgroup\$Razetime– Razetime2021年02月17日 03:09:17 +00:00Commented Feb 17, 2021 at 3:09
R, 12 bytes
Sys.time()+n
This returns a full date, the year is at the beginning of the string. This is according to the rules, which didn't say to print just the year; and this is not in the list of "standard loopholes" by the time of this answer.
To print just a year, R would need 25 bytes:
format(Sys.time()+n,"%Y")
-
1\$\begingroup\$ Even if you used the
formatsolution, you still would have the shortestRanswer. \$\endgroup\$user100690– user1006902021年02月16日 10:38:27 +00:00Commented Feb 16, 2021 at 10:38 -
1\$\begingroup\$ Actually, I think the ISO specification only requires 4-digit years, so you can use
substr(...,1,4)which is a byte shorter. \$\endgroup\$JDL– JDL2021年02月17日 15:17:34 +00:00Commented Feb 17, 2021 at 15:17 -
\$\begingroup\$ @JDL thanks for the idea! :-) But not sure we can rely that the year will be 4-digit after addition/subtraction? More general
sub("-.*","",Sys.time()+n)would work but is one char longer. \$\endgroup\$Tomas– Tomas2021年02月17日 18:48:02 +00:00Commented Feb 17, 2021 at 18:48 -
\$\begingroup\$ @Tomas I don't think that matters if you interpret the rules as meaning the output is undefined if it would give rise to a year > 9999. From the wikipedia page: "ISO 8601 prescribes, as a minimum, a four-digit year [YYYY] to avoid the year 2000 problem. It therefore represents years from 0000 to 9999" \$\endgroup\$JDL– JDL2021年02月18日 12:01:33 +00:00Commented Feb 18, 2021 at 12:01
IBM/Lotus Notes Formula Language, (削除) 34 (削除ここまで) 32 Bytes
@Year(@Adjust(@Now;0;0;0;0;0;i))
Takes input from a field named i. Unfortunately, Formula only supports 32 bit signed integers so it is restricted to a maximum input of +/- 2,147,483,647.
There is no TIO for Formula so here are a couple of screenshots:
enter image description here enter image description here enter image description here enter image description here
MATL, 11 bytes
12L/Z'+10XO
Try it out at MATL Online
Explanation
% Implicitly grab input as an integer (seconds)
12L % Push the literal 86400 to the stack (seconds in a day)
/ % Divide the input (in seconds) by the seconds in a day to convert to days
Z' % Get the current time in days as a float
+ % Add the current time and the seconds in the future together
10XQ % Determine the year of this date
% Implicitly display the result
-
\$\begingroup\$ not all days are 86400 seconds long! \$\endgroup\$Agos– Agos2021年02月17日 10:07:28 +00:00Commented Feb 17, 2021 at 10:07
-
1\$\begingroup\$ Hey, @Suever, it's been long! :-D Regarding what Agos says, I have asked the OP if leap seconds need to be taken into account (which would be very difficult) \$\endgroup\$Luis Mendo– Luis Mendo2021年02月17日 11:03:01 +00:00Commented Feb 17, 2021 at 11:03
-
2\$\begingroup\$ OP has confirmed it is not necessary \$\endgroup\$Luis Mendo– Luis Mendo2021年02月17日 13:17:57 +00:00Commented Feb 17, 2021 at 13:17
-
1\$\begingroup\$ As
strftime()returns string and in AWK even 0 is truthy as long as it's string, you can reduce it to1ドル=strftime("%Y",1ドル+systime()), because will always produce output.. \$\endgroup\$manatwork– manatwork2021年02月16日 00:14:50 +00:00Commented Feb 16, 2021 at 0:14 -
\$\begingroup\$ @manatwork thanks! that saves 5 bytes! \$\endgroup\$Digital Trauma– Digital Trauma2021年02月16日 00:57:41 +00:00Commented Feb 16, 2021 at 0:57
GNU coreutils (16 bytes)
date +%Y -d1ドルsec
Saved 4 bytes, thanks to @ovs.
-
\$\begingroup\$ You can remove the
ondsfromseconds: Try it online! \$\endgroup\$ovs– ovs2021年02月16日 08:28:51 +00:00Commented Feb 16, 2021 at 8:28 -
\$\begingroup\$ @ovs ah, I tried
sandsecsbut missedsecsomehow, thanks \$\endgroup\$rexkogitans– rexkogitans2021年02月16日 08:31:45 +00:00Commented Feb 16, 2021 at 8:31 -
\$\begingroup\$ Unfortunately, this is a dupe of 2x-1's answer (label for Bash) codegolf.stackexchange.com/a/219053/55953 \$\endgroup\$CSM– CSM2021年02月16日 10:40:28 +00:00Commented Feb 16, 2021 at 10:40
-
\$\begingroup\$ @CSM really oops. I only looked if someone posted for GNU coreutils, bash slipped my attention. \$\endgroup\$rexkogitans– rexkogitans2021年02月16日 12:34:05 +00:00Commented Feb 16, 2021 at 12:34
-
MySQL, 35 bytes
select year(now()+interval [input] second)
Java (JDK), 57 bytes
n->java.time.LocalDateTime.now().plusSeconds(n).getYear()
Beats the Date API (71 bytes):
n->new java.util.Date(System.currentTimeMillis()+n*1000).getYear()+1900
Note that this one returns the year in absolute form (no negative year).
And I don't even speak about the Calendar API.
C# (.NET Core), 98 bytes
public class E{public static void m(double x){Console.WriteLine(DateTime.Now.AddSeconds(x).Year);}
Didn't count the using System; and calling function in Main(), if they needed to be added, please inform me!
-
\$\begingroup\$ Still a fine solution, but I kinda doubt whether C# is an appropriate golfing language. \$\endgroup\$user100690– user1006902021年02月15日 16:35:06 +00:00Commented Feb 15, 2021 at 16:35
-
1\$\begingroup\$ @expressjs123 C# is a valid golfing language and has been used in many questions, still they are harder to golf \$\endgroup\$avarice– avarice2021年02月15日 16:36:52 +00:00Commented Feb 15, 2021 at 16:36
-
\$\begingroup\$ Can probably cut this down using the C# interactive window.. \$\endgroup\$Caius Jard– Caius Jard2021年02月15日 22:25:33 +00:00Commented Feb 15, 2021 at 22:25
-
9\$\begingroup\$ You can golf in any language. I don't normally consider getting the best overall score all that interesting (since many golfing languages can solve a problem in only a couple of bytes) but prefer seeing the best score possible in a language that people use for everyday programming. \$\endgroup\$Turksarama– Turksarama2021年02月15日 22:28:17 +00:00Commented Feb 15, 2021 at 22:28
Visual Basic .NET (VBC), 89 bytes
public class E
Shared sub m(x)
Console.WriteLine(DateTime.Now.AddSeconds(x).Year)
end Sub
VBScript, 52 bytes
MsgBox Year(DateAdd("s",Wscript.Arguments(0),Now())
AppleScript function, 46
to y(s)
(current date+s/60*minutes)'s year
end
Test driver:
repeat with sec in {100000000000, 1000, 54398643, 54398643234, -100000000000}
log y(sec)
end repeat
Save the function and the test driver as text to nseconds.applescript, then run in the terminal:
osascript nseconds.applescript
Or run in the AppleScript Editor app.
T-SQL, 42 bytes
select year(dateadd(s,a,getdate()))from t;
Uses the standard input method for T-SQL of taking input from a table. You can create a suitable table like this:
create table t (a int not null);
insert into t values (1000000000), (1000), (54398643), (-1000000000);
Note that T-SQL is limited to 32-bit integers for the number of seconds. To avoid that and allow the resulting year to vary between 0 and 9999 costs 6 bytes:
select year(dateadd(d,a/86400,getdate()))from t;
Don't forget to declare a as bigint if you do this. (Note that hours is represented by hh so it's no shorter, and minutes won't let you reach 9999.)
APL (Dyalog Unicode), 20 bytes (SBCS)
Full program, prompting for n from stdin.
⊃⊃20 ̄1⎕DT⎕+20⎕DT'J'
20⎕DT'J' get current local* (Juliett) DateTime as UNIX time (code 20; seconds from beginning of 1970)
⎕+ prompt for n and use that to increment the UNIX time.
20 ̄1 interpret as UNIX times (code 20) and convert to an array of time stamps (code -1)
⊃ extract the first (and only) time stamp
⊃ extract the first element (the year)
Try APL! (first and last case scaled down by a factor of 10 to avoid hitting date-time limits, 1 January 0001 though 28 February 4000; turned into function for ease of use)
* could also have 'Z' (Zulu) to use the current UTC time instead of local time.
-
\$\begingroup\$ I don't really understand APL, so I don't entirely know what the problem is, but when I paste your code into
tryaplit gives me an error? \$\endgroup\$user100690– user1006902021年02月15日 14:17:00 +00:00Commented Feb 15, 2021 at 14:17 -
\$\begingroup\$ @expressjs123 tryAPL uses a safe version of APL which prevents people from running malicious code, so it'll give you an error for using
⎕. \$\endgroup\$Razetime– Razetime2021年02月15日 14:43:17 +00:00Commented Feb 15, 2021 at 14:43 -
\$\begingroup\$ Lots of multibyte unicode characters here, "echo '⊃⊃20 ¯1⎕DT⎕+20⎕DT\'J\'' | wc -c" gives me 32 which after removing the newline makes 31 bytes. \$\endgroup\$timthelion– timthelion2021年02月16日 17:16:13 +00:00Commented Feb 16, 2021 at 17:16
-
\$\begingroup\$ @timthelion Sorry about that. Fixed now. \$\endgroup\$Adám– Adám2021年02月16日 17:17:10 +00:00Commented Feb 16, 2021 at 17:17
Mathematica, 43 bytes
IntegerPart@DatePlus[#/86400]["YearExact"]&
Thanks to @LegionMammal978 for hinting that DatePlus[#/86400][[1,1]]& fails for negative years
-
1\$\begingroup\$ This fails on negative year numbers. \$\endgroup\$LegionMammal978– LegionMammal9782021年02月16日 03:08:05 +00:00Commented Feb 16, 2021 at 3:08
-
\$\begingroup\$ @LegionMammal978 oh... you're absolutely right! thanks, guess i'll have to add a few more bytes :-/ \$\endgroup\$sanchez– sanchez2021年02月16日 21:36:45 +00:00Commented Feb 16, 2021 at 21:36
-
new Date()gives the date at my local time, but that might not be true in other languages. It depends on the language \$\endgroup\$sleep $n;datebeing a valid bash answer? I notice there's no performance requirement :P \$\endgroup\$