Unix timestamp to datetime string
$begingroup$
Given a unix timestamp as an input, give a datetime string, in a format like so: "YYMMDD.HHmm"
Rules
- The input is a number (integer) of a millisecond-precise UNIX epoch time (milliseconds since 1970 January 1st 00:00:00.000 UTC).
- The values must be padded with zeroes if they are 1 character instead of 2. (e.g.: for "DD", "1" is not acceptable, but "01" is.)
- The output must be a single string. No arrays.
- Leap second handling doesn't matter.
- Shortest wins.
Good luck!
Example
Input: 1547233866744
Output: 190111.1911
code-golf date
$endgroup$
|
show 12 more comments
$begingroup$
Given a unix timestamp as an input, give a datetime string, in a format like so: "YYMMDD.HHmm"
Rules
- The input is a number (integer) of a millisecond-precise UNIX epoch time (milliseconds since 1970 January 1st 00:00:00.000 UTC).
- The values must be padded with zeroes if they are 1 character instead of 2. (e.g.: for "DD", "1" is not acceptable, but "01" is.)
- The output must be a single string. No arrays.
- Leap second handling doesn't matter.
- Shortest wins.
Good luck!
Example
Input: 1547233866744
Output: 190111.1911
code-golf date
$endgroup$
2
$begingroup$
Welcome to PPCG! Nice challenge, but there are a few clarifications to be made. To make the challenge self-contained, you should probably explain what the Unix epoch is. Additionally, what should be done with leap seconds? What should be done with the Year 2038 problem?
$endgroup$
– AdmBorkBork
Jan 11 at 19:43
1
$begingroup$
@AdmBorkBork Edited the post to explain what the Unix epoch is. Leap second implementation doesn't matter, since the output string is not second-precise. The Year 2038 problem doesn't currently matter since it could be a limitation of the running device or the chosen programming language.
$endgroup$
– skiilaa
Jan 11 at 19:50
1
$begingroup$
Does the timezone matter?
$endgroup$
– Erik the Outgolfer
Jan 11 at 21:52
$begingroup$
I take it the year is represented by a two digit number?
$endgroup$
– Embodiment of Ignorance
Jan 11 at 22:22
1
$begingroup$
@FabianRöling timezones don't matter.
$endgroup$
– skiilaa
Jan 12 at 18:04
|
show 12 more comments
$begingroup$
Given a unix timestamp as an input, give a datetime string, in a format like so: "YYMMDD.HHmm"
Rules
- The input is a number (integer) of a millisecond-precise UNIX epoch time (milliseconds since 1970 January 1st 00:00:00.000 UTC).
- The values must be padded with zeroes if they are 1 character instead of 2. (e.g.: for "DD", "1" is not acceptable, but "01" is.)
- The output must be a single string. No arrays.
- Leap second handling doesn't matter.
- Shortest wins.
Good luck!
Example
Input: 1547233866744
Output: 190111.1911
code-golf date
$endgroup$
Given a unix timestamp as an input, give a datetime string, in a format like so: "YYMMDD.HHmm"
Rules
- The input is a number (integer) of a millisecond-precise UNIX epoch time (milliseconds since 1970 January 1st 00:00:00.000 UTC).
- The values must be padded with zeroes if they are 1 character instead of 2. (e.g.: for "DD", "1" is not acceptable, but "01" is.)
- The output must be a single string. No arrays.
- Leap second handling doesn't matter.
- Shortest wins.
Good luck!
Example
Input: 1547233866744
Output: 190111.1911
code-golf date
code-golf date
edited Jan 12 at 21:57
Community♦
1
1
asked Jan 11 at 19:27
skiilaaskiilaa
1638
1638
2
$begingroup$
Welcome to PPCG! Nice challenge, but there are a few clarifications to be made. To make the challenge self-contained, you should probably explain what the Unix epoch is. Additionally, what should be done with leap seconds? What should be done with the Year 2038 problem?
$endgroup$
– AdmBorkBork
Jan 11 at 19:43
1
$begingroup$
@AdmBorkBork Edited the post to explain what the Unix epoch is. Leap second implementation doesn't matter, since the output string is not second-precise. The Year 2038 problem doesn't currently matter since it could be a limitation of the running device or the chosen programming language.
$endgroup$
– skiilaa
Jan 11 at 19:50
1
$begingroup$
Does the timezone matter?
$endgroup$
– Erik the Outgolfer
Jan 11 at 21:52
$begingroup$
I take it the year is represented by a two digit number?
$endgroup$
– Embodiment of Ignorance
Jan 11 at 22:22
1
$begingroup$
@FabianRöling timezones don't matter.
$endgroup$
– skiilaa
Jan 12 at 18:04
|
show 12 more comments
2
$begingroup$
Welcome to PPCG! Nice challenge, but there are a few clarifications to be made. To make the challenge self-contained, you should probably explain what the Unix epoch is. Additionally, what should be done with leap seconds? What should be done with the Year 2038 problem?
$endgroup$
– AdmBorkBork
Jan 11 at 19:43
1
$begingroup$
@AdmBorkBork Edited the post to explain what the Unix epoch is. Leap second implementation doesn't matter, since the output string is not second-precise. The Year 2038 problem doesn't currently matter since it could be a limitation of the running device or the chosen programming language.
$endgroup$
– skiilaa
Jan 11 at 19:50
1
$begingroup$
Does the timezone matter?
$endgroup$
– Erik the Outgolfer
Jan 11 at 21:52
$begingroup$
I take it the year is represented by a two digit number?
$endgroup$
– Embodiment of Ignorance
Jan 11 at 22:22
1
$begingroup$
@FabianRöling timezones don't matter.
$endgroup$
– skiilaa
Jan 12 at 18:04
2
2
$begingroup$
Welcome to PPCG! Nice challenge, but there are a few clarifications to be made. To make the challenge self-contained, you should probably explain what the Unix epoch is. Additionally, what should be done with leap seconds? What should be done with the Year 2038 problem?
$endgroup$
– AdmBorkBork
Jan 11 at 19:43
$begingroup$
Welcome to PPCG! Nice challenge, but there are a few clarifications to be made. To make the challenge self-contained, you should probably explain what the Unix epoch is. Additionally, what should be done with leap seconds? What should be done with the Year 2038 problem?
$endgroup$
– AdmBorkBork
Jan 11 at 19:43
1
1
$begingroup$
@AdmBorkBork Edited the post to explain what the Unix epoch is. Leap second implementation doesn't matter, since the output string is not second-precise. The Year 2038 problem doesn't currently matter since it could be a limitation of the running device or the chosen programming language.
$endgroup$
– skiilaa
Jan 11 at 19:50
$begingroup$
@AdmBorkBork Edited the post to explain what the Unix epoch is. Leap second implementation doesn't matter, since the output string is not second-precise. The Year 2038 problem doesn't currently matter since it could be a limitation of the running device or the chosen programming language.
$endgroup$
– skiilaa
Jan 11 at 19:50
1
1
$begingroup$
Does the timezone matter?
$endgroup$
– Erik the Outgolfer
Jan 11 at 21:52
$begingroup$
Does the timezone matter?
$endgroup$
– Erik the Outgolfer
Jan 11 at 21:52
$begingroup$
I take it the year is represented by a two digit number?
$endgroup$
– Embodiment of Ignorance
Jan 11 at 22:22
$begingroup$
I take it the year is represented by a two digit number?
$endgroup$
– Embodiment of Ignorance
Jan 11 at 22:22
1
1
$begingroup$
@FabianRöling timezones don't matter.
$endgroup$
– skiilaa
Jan 12 at 18:04
$begingroup$
@FabianRöling timezones don't matter.
$endgroup$
– skiilaa
Jan 12 at 18:04
|
show 12 more comments
21 Answers
21
active
oldest
votes
$begingroup$
Japt v1.4.5, 19 16 bytes
GîÐU s3)¤o>J i.G
1 byte saved thanks to Oliver, which led to another 2 bytes saved.
Try it
Explanation
GîÐU s3)¤o>J i.G
:Implicit input of integer U
G :16
î :Get the first 16 characters of the following string
ÐU : Convert U to a date object
s3 : Convert to ISO string
) :End get
¤ :Slice off the first 2 characters
o :Filter
>J : Greater than -1
i.G :Insert "." at 0-based index 16, with wrapping
Notes / Tips
- Getting the first 16 characters of the ISO string and then slicing off the first two is a byte shorter than performing a single slice.
G
is used to insert the.
at the required index because using a literal6
would cause it to be combined with the.
and for that to be interpreted as a decimal that would be inserted at the start of the string. To get around that I'd need to add a'
before the.
to force it to be interpreted as a string.- Japt v1.4.5 is used because Japt doesn't have a constant for
17
and from v1.4.6 on trying to insert something at the first index past the end of a string results in it being inserted at the end of the string (A
is the Japt constant for10
) whereas prior to v1.4.6 it immediately wraps back to the beginning of the string.
$endgroup$
add a comment |
$begingroup$
JavaScript (ES6), 65 bytes
n=>'101010.1010'.replace(i=/d/g,x=>new Date(n).toJSON()[i=x-~i])
Try it online!
How?
We initialize the pointer $i$ to a non-numeric value (coerced to $0$) and then add alternately $2$ and $1$ to it to pick the relevant characters from the ISO-8601 conversion of the input timestamp.
yyyy-mm-ddThh:mm:ss.sssZ
^^ ^^ ^^ ^^ ^^
JavaScript (ES6), 66 bytes
n=>'235689.BCEF'.replace(/w/g,x=>new Date(n).toJSON()[+`0x${x}`])
Try it online!
How?
Once the input timestamp is converted in ISO-8601 format, all required characters can be accessed with a single hexadecimal digit.
yyyy-mm-ddThh:mm:ss.sssZ
↓↓ ↓↓ ↓↓ ↓↓ ↓↓
0123456789ABCDEF
$endgroup$
$begingroup$
Wow. Just, wow.
$endgroup$
– skiilaa
Jan 13 at 9:08
1
$begingroup$
64 bytes:n=>'235689.11121415'.replace(/1?w/g,x=>new Date(n).toJSON()[x])
$endgroup$
– tsh
Jan 14 at 7:02
$begingroup$
@tsh Nice! I was not expecting the decimal format to be shorter. You may want to post this as a separate answer.
$endgroup$
– Arnauld
Jan 14 at 15:45
add a comment |
$begingroup$
Bash + coreutils, 29 bytes
date -d@${1::-3} +%y%m%d.%H%M
Try it online!
$endgroup$
add a comment |
$begingroup$
PHP, 40 32 31 bytes
-8 bytes thanks to Luis felipe
-1 byte thanks to Jo King
<?=date('ymd.hi',$argv[1]/1e3);
Try it online!
Simple naive answer. PHP's date
function takes a format string and an integer timestamp. Input from cli arguments, which is a string by default, then /1e3
because date
expects second-precise timestamps. This also coerces the string to a number.
$endgroup$
$begingroup$
Nice answer! It's a tad shorter if the language has date formatting, yes :)
$endgroup$
– skiilaa
Jan 11 at 20:03
$begingroup$
32 bytes you dont need to cast to integer since"2"/1
will cast automatically the string
$endgroup$
– Luis felipe De jesus Munoz
Jan 11 at 20:04
$begingroup$
ah of course, I added intval before realising I needed/1000
, and didn't think that I mihgt not need it afterwards :P
$endgroup$
– Skidsdev
Jan 11 at 20:08
$begingroup$
@JoKing ah nice one, thanks
$endgroup$
– Skidsdev
Jan 14 at 14:03
add a comment |
$begingroup$
MATL, 28 bytes
Thanks to @skiilaa for a correction in the output format.
864e5/719529+'YYmmDD.HHMM'XO
Try it online!
Explanation
MATL, like MATLAB, defines date/time numbers as the (possibly non-integer) number of days since time 00:00 of the reference "date" 0-Jan-0000.
Thus we take the input, divide it by 86400000 (number of milliseconds in one day), add 719529 (number of days from MATL's reference to UNIX reference), and convert to the desired format 'YYmmDD.HHMM'.
$endgroup$
add a comment |
$begingroup$
GNU AWK, 34 33 characters
$0=strftime("%y%m%d.%H%M",$0/1e3)
(strftime()
is GNU extension, will not run in other AWK implementations.)
Thanks to:
Jo King for suggesting E-notation (-1 character)
Sampler run:
bash-4.4$ awk '$0=strftime("%y%m%d.%H%M",$0/1e3)' <<< 1547233866744
190111.2111
Try it online!
$endgroup$
$begingroup$
Thank you, @JoKing. Unfortunately E-notation is not really my friend so I always forget it.
$endgroup$
– manatwork
Jan 13 at 16:02
add a comment |
$begingroup$
PowerShell, 59 58 bytes
"{0:yyMMdd.HHmm}"-f(Date 1/1/1970).AddSeconds("$args"/1e3)
Try it online!
Gets the Date
of 1/1/1970
(defaults to 00:00:00am), then Add
s the appropriate number of Seconds
. Passes that to the -f
ormat operator, which correctly formats the datetime.
Probably culture-dependent. This works on TIO, which is en-us
.
-1 byte thanks to shaggy.
$endgroup$
add a comment |
$begingroup$
Perl 6, 111 89 87 bytes
{~DateTime.new($_/Ⅿ,:formatter{"{(.year%Ⅽ,.month,.day).fmt('%02d','')}.{(.hour,.minute).fmt('%02d','')}"})}
Try it (111)
{TR/-//}o{S/..//}o{.yyyy-mm-dd~'.'~(.hour,.minute).fmt('%02d','')}o{DateTime.new($_/Ⅿ)}
Try it (89)
{TR/- //}o{S/..//}o{.yyyy-mm-dd~'.'~(.hour,.minute).fmt('%02d')}o{DateTime.new($_/Ⅿ)}
Try it (87)
Explanation:
The o
infix operator takes two functions and creates a composite function. The rightmost one gets called first, and the one to the left gets called with its result.
Basically we use 4 block lambdas to generate a single lambda.
Which is not much different to how a WhateverCode lambda like * + *
gets created.
Divide by 1000 and use that to create a DateTime object.
{DateTime.new($_/Ⅿ)} # Ⅿ is ROMAN NUMERAL ONE THOUSAND (3 bytes)
The result gets used by:
{
.yyyy-mm-dd # 2019-01-11
~ '.' ~ # str concatenation with '.'
( .hour, .minute ).fmt('%02d') # add leading 0s (returns List)
}
That leaves us with a string like 2019-01-11.19 11
We need to remove the first two digits
{S/..//}
We also need to remove -
and
{TR/- //}
$endgroup$
add a comment |
$begingroup$
Python 2, 64 bytes
lambda s:strftime('%y%m%d.%H%M',gmtime(s/1e3))
from time import*
Try it online!
The input is considered to be in UTC.
$endgroup$
1
$begingroup$
Just as something I've been a bit confused on, is the only reason that thelambda
comes before theimport
because it works better for TIO's header?
$endgroup$
– Neil A.
Jan 11 at 22:43
2
$begingroup$
@NeilA. Yes. The import can go either before or after, the contents of the lambda aren't checked forNameError
s before it's called.
$endgroup$
– Erik the Outgolfer
Jan 11 at 22:45
add a comment |
$begingroup$
R, 58 56 bytes
format(as.POSIXct(scan()/1e3,,'1970-1-1'),'%y%m%d.%H%M')
Try it online!
$endgroup$
add a comment |
$begingroup$
C (gcc) (32-bit, little endian), 67 bytes
f(t,s)long long t;{t/=1e3;strftime(s,12,"%y%m%d.%H%M",gmtime(&t));}
Try it online!
On an ILP64 platform, the following 55 byte version should work:
f(t,s){t/=1e3;strftime(s,12,"%y%m%d.%H%M",gmtime(&t));}
$endgroup$
$begingroup$
What's the extras
argument you're taking for?
$endgroup$
– Shaggy
Jan 12 at 14:47
1
$begingroup$
@Shaggy Thes
is for the output string.
$endgroup$
– nwellnhof
Jan 12 at 15:06
$begingroup$
It looks like you're initiating it outside the function; do we have a meta consensus that allows C to do that?
$endgroup$
– Shaggy
Jan 12 at 15:31
$begingroup$
@Shaggy I'm not sure what "consensus" means exactly but here's the relevant meta post.
$endgroup$
– nwellnhof
Jan 12 at 15:54
$begingroup$
With "32-bit,", whylong long
instead oflong
orint32_t
,int64_t
,time_t
? IAC, all shorter thanlong long
.
$endgroup$
– chux
Jan 13 at 22:23
|
show 2 more comments
$begingroup$
Perl 6, 57 50 bytes
{TR:d/T:-/./}o{substr ~DateTime.new($_/1e3): 2,15}
Try it online!
Takes the default stringification of a Datetime, in the format yyyy-mm-ddThh:mm:ssZ
and modifies it to fit the output format. Perl 6 is in need of a date formatter method.
Explanation:
Datetime.new($_/1e3) # Create a date time
~ # Stringify it to the format yyyy-mm-ddThh:mm:ssZ
# e.g. 2019-01-11T19:11:06.744000Z
substr : 2,15 # Take the middle 15 characters
{TR:d/T /./}o # Then replace 'T' with '.'
:- # Then remove ':' and '-'
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 67 61 60 bytes
n=>$"{new DateTime(1970,1,1).AddTicks(n*10000):yyMMdd.HHmm}"
For reasons unknown to me, DateTime.UnixEpoch doesn't work.
Try it online!
$endgroup$
1
$begingroup$
It seems UnixEpoch is only present in.Net Core 2.1+
$endgroup$
– digEmAll
Jan 12 at 12:19
add a comment |
$begingroup$
Javascript ES6, 76 66 bytes
x=>new Date(x).toJSON().slice(2,16).replace(/D/g,a=>a>'S'?'.':'')
Try it online
-10 bytes thanks to Shaggy!
x // timestamp
=>
new Date(x) // date object from timestamp
.toJSON() // same as .toISOString()
.slice(2,16) // cut off excess
.replace(/D/g, // match all non-digits
a // a is matched character
=>
a>'S'?'.' // if a is T (bigger than S is shorter) replace it with .
:'' // if it's not T, replace it with nothing
// this way the dashes get removed and the dot gets put in the right place
) // end of replace
$endgroup$
3
$begingroup$
You may want to wait a day or so before answering your own questions next time.
$endgroup$
– fəˈnɛtɪk
Jan 11 at 20:11
$begingroup$
71 bytes
$endgroup$
– Luis felipe De jesus Munoz
Jan 11 at 20:16
$begingroup$
Alternative 71 bytes
$endgroup$
– Shaggy
Jan 11 at 20:33
1
$begingroup$
@LuisfelipeDejesusMunoz, that's different enough for you to post yourself.
$endgroup$
– Shaggy
Jan 11 at 21:49
$begingroup$
@LuisfelipeDejesusMunoz 66 bytes to tie you with Arnauld.
$endgroup$
– Shaggy
Jan 12 at 13:50
add a comment |
$begingroup$
C (clang), 117 111 bytes
Thanks to @chux and @ceilingcat for the suggestions.
#import<time.h>
*l;f(long t){t/=1e3;printf("%02d%02d%02d.%02d%02d",5[l=gmtime(&t)]%100,l[4]+1,l[3],l[2],l[1]);}
Try it online!
$endgroup$
$begingroup$
gmtime
is short thanlocaltime
$endgroup$
– chux
Jan 13 at 22:08
add a comment |
$begingroup$
Twig, 25 characters
{{d[:-3]|date('ymd.hi')}}
This is a template. Call it by including it and pass the Unix time as parameter d.
Sample usage:
{{include('datetime.twig', {'d': 1547233866744})}}
Try it on TwigFiddle
$endgroup$
add a comment |
$begingroup$
JavaScript, 64 bytes
n=>'2356891911121415'.replace(/1?./g,x=>new Date(n).toJSON()[x])
Try it online!
$endgroup$
$begingroup$
aw, so close
$endgroup$
– ASCII-only
Jan 15 at 5:47
$begingroup$
also 64
$endgroup$
– ASCII-only
Jan 15 at 5:48
add a comment |
$begingroup$
jq, 33 characters
(30 characters code + 3 characters command line option)
./1000|strftime("%y%m%d.%H%M")
Sample run:
bash-4.4$ jq -r './1000|strftime("%y%m%d.%H%M")' <<< 1547233866744
190111.1911
Try it online!
$endgroup$
3
$begingroup$
You don't need to count command-line flags anymore.
$endgroup$
– AdmBorkBork
Jan 11 at 20:28
$begingroup$
Oops. Good to know. Thank you @AdmBorkBork.
$endgroup$
– manatwork
Jan 11 at 20:36
$begingroup$
1000
->1e3
$endgroup$
– Shaggy
Jan 14 at 20:16
add a comment |
$begingroup$
ksh, 36 bytes
printf "%(%y%m%d.%H%M)T" $(($1/1e3))
Try it online!
Thanks to Jo King for 15 bytes saved
$endgroup$
$begingroup$
The same in Bash would be just 35 characters: Try it online!
$endgroup$
– manatwork
Jan 13 at 15:25
add a comment |
$begingroup$
MediaWiki, 46 bytes
{{#time:ymd.Hi|@{{#expr:floor({{{1}}}/1e3)}}}}
$endgroup$
add a comment |
$begingroup$
Java 8, 78 bytes
n->new java.text.SimpleDateFormat("yyMMdd.HHmm").format(new java.util.Date(n))
Try it online.
Explanation:
n-> // Method with long parameter and String return-type
new java.text.SimpleDateFormat("yyMMdd.HHmm")
// Create the formatter
.format( // Format the date to a String in this format and return it:
new java.util.Date( // Create a new Date
n)) // With the input-long as timestamp
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "200"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f178662%2funix-timestamp-to-datetime-string%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
21 Answers
21
active
oldest
votes
21 Answers
21
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Japt v1.4.5, 19 16 bytes
GîÐU s3)¤o>J i.G
1 byte saved thanks to Oliver, which led to another 2 bytes saved.
Try it
Explanation
GîÐU s3)¤o>J i.G
:Implicit input of integer U
G :16
î :Get the first 16 characters of the following string
ÐU : Convert U to a date object
s3 : Convert to ISO string
) :End get
¤ :Slice off the first 2 characters
o :Filter
>J : Greater than -1
i.G :Insert "." at 0-based index 16, with wrapping
Notes / Tips
- Getting the first 16 characters of the ISO string and then slicing off the first two is a byte shorter than performing a single slice.
G
is used to insert the.
at the required index because using a literal6
would cause it to be combined with the.
and for that to be interpreted as a decimal that would be inserted at the start of the string. To get around that I'd need to add a'
before the.
to force it to be interpreted as a string.- Japt v1.4.5 is used because Japt doesn't have a constant for
17
and from v1.4.6 on trying to insert something at the first index past the end of a string results in it being inserted at the end of the string (A
is the Japt constant for10
) whereas prior to v1.4.6 it immediately wraps back to the beginning of the string.
$endgroup$
add a comment |
$begingroup$
Japt v1.4.5, 19 16 bytes
GîÐU s3)¤o>J i.G
1 byte saved thanks to Oliver, which led to another 2 bytes saved.
Try it
Explanation
GîÐU s3)¤o>J i.G
:Implicit input of integer U
G :16
î :Get the first 16 characters of the following string
ÐU : Convert U to a date object
s3 : Convert to ISO string
) :End get
¤ :Slice off the first 2 characters
o :Filter
>J : Greater than -1
i.G :Insert "." at 0-based index 16, with wrapping
Notes / Tips
- Getting the first 16 characters of the ISO string and then slicing off the first two is a byte shorter than performing a single slice.
G
is used to insert the.
at the required index because using a literal6
would cause it to be combined with the.
and for that to be interpreted as a decimal that would be inserted at the start of the string. To get around that I'd need to add a'
before the.
to force it to be interpreted as a string.- Japt v1.4.5 is used because Japt doesn't have a constant for
17
and from v1.4.6 on trying to insert something at the first index past the end of a string results in it being inserted at the end of the string (A
is the Japt constant for10
) whereas prior to v1.4.6 it immediately wraps back to the beginning of the string.
$endgroup$
add a comment |
$begingroup$
Japt v1.4.5, 19 16 bytes
GîÐU s3)¤o>J i.G
1 byte saved thanks to Oliver, which led to another 2 bytes saved.
Try it
Explanation
GîÐU s3)¤o>J i.G
:Implicit input of integer U
G :16
î :Get the first 16 characters of the following string
ÐU : Convert U to a date object
s3 : Convert to ISO string
) :End get
¤ :Slice off the first 2 characters
o :Filter
>J : Greater than -1
i.G :Insert "." at 0-based index 16, with wrapping
Notes / Tips
- Getting the first 16 characters of the ISO string and then slicing off the first two is a byte shorter than performing a single slice.
G
is used to insert the.
at the required index because using a literal6
would cause it to be combined with the.
and for that to be interpreted as a decimal that would be inserted at the start of the string. To get around that I'd need to add a'
before the.
to force it to be interpreted as a string.- Japt v1.4.5 is used because Japt doesn't have a constant for
17
and from v1.4.6 on trying to insert something at the first index past the end of a string results in it being inserted at the end of the string (A
is the Japt constant for10
) whereas prior to v1.4.6 it immediately wraps back to the beginning of the string.
$endgroup$
Japt v1.4.5, 19 16 bytes
GîÐU s3)¤o>J i.G
1 byte saved thanks to Oliver, which led to another 2 bytes saved.
Try it
Explanation
GîÐU s3)¤o>J i.G
:Implicit input of integer U
G :16
î :Get the first 16 characters of the following string
ÐU : Convert U to a date object
s3 : Convert to ISO string
) :End get
¤ :Slice off the first 2 characters
o :Filter
>J : Greater than -1
i.G :Insert "." at 0-based index 16, with wrapping
Notes / Tips
- Getting the first 16 characters of the ISO string and then slicing off the first two is a byte shorter than performing a single slice.
G
is used to insert the.
at the required index because using a literal6
would cause it to be combined with the.
and for that to be interpreted as a decimal that would be inserted at the start of the string. To get around that I'd need to add a'
before the.
to force it to be interpreted as a string.- Japt v1.4.5 is used because Japt doesn't have a constant for
17
and from v1.4.6 on trying to insert something at the first index past the end of a string results in it being inserted at the end of the string (A
is the Japt constant for10
) whereas prior to v1.4.6 it immediately wraps back to the beginning of the string.
edited Jan 14 at 18:44
answered Jan 11 at 22:34
ShaggyShaggy
19.5k21666
19.5k21666
add a comment |
add a comment |
$begingroup$
JavaScript (ES6), 65 bytes
n=>'101010.1010'.replace(i=/d/g,x=>new Date(n).toJSON()[i=x-~i])
Try it online!
How?
We initialize the pointer $i$ to a non-numeric value (coerced to $0$) and then add alternately $2$ and $1$ to it to pick the relevant characters from the ISO-8601 conversion of the input timestamp.
yyyy-mm-ddThh:mm:ss.sssZ
^^ ^^ ^^ ^^ ^^
JavaScript (ES6), 66 bytes
n=>'235689.BCEF'.replace(/w/g,x=>new Date(n).toJSON()[+`0x${x}`])
Try it online!
How?
Once the input timestamp is converted in ISO-8601 format, all required characters can be accessed with a single hexadecimal digit.
yyyy-mm-ddThh:mm:ss.sssZ
↓↓ ↓↓ ↓↓ ↓↓ ↓↓
0123456789ABCDEF
$endgroup$
$begingroup$
Wow. Just, wow.
$endgroup$
– skiilaa
Jan 13 at 9:08
1
$begingroup$
64 bytes:n=>'235689.11121415'.replace(/1?w/g,x=>new Date(n).toJSON()[x])
$endgroup$
– tsh
Jan 14 at 7:02
$begingroup$
@tsh Nice! I was not expecting the decimal format to be shorter. You may want to post this as a separate answer.
$endgroup$
– Arnauld
Jan 14 at 15:45
add a comment |
$begingroup$
JavaScript (ES6), 65 bytes
n=>'101010.1010'.replace(i=/d/g,x=>new Date(n).toJSON()[i=x-~i])
Try it online!
How?
We initialize the pointer $i$ to a non-numeric value (coerced to $0$) and then add alternately $2$ and $1$ to it to pick the relevant characters from the ISO-8601 conversion of the input timestamp.
yyyy-mm-ddThh:mm:ss.sssZ
^^ ^^ ^^ ^^ ^^
JavaScript (ES6), 66 bytes
n=>'235689.BCEF'.replace(/w/g,x=>new Date(n).toJSON()[+`0x${x}`])
Try it online!
How?
Once the input timestamp is converted in ISO-8601 format, all required characters can be accessed with a single hexadecimal digit.
yyyy-mm-ddThh:mm:ss.sssZ
↓↓ ↓↓ ↓↓ ↓↓ ↓↓
0123456789ABCDEF
$endgroup$
$begingroup$
Wow. Just, wow.
$endgroup$
– skiilaa
Jan 13 at 9:08
1
$begingroup$
64 bytes:n=>'235689.11121415'.replace(/1?w/g,x=>new Date(n).toJSON()[x])
$endgroup$
– tsh
Jan 14 at 7:02
$begingroup$
@tsh Nice! I was not expecting the decimal format to be shorter. You may want to post this as a separate answer.
$endgroup$
– Arnauld
Jan 14 at 15:45
add a comment |
$begingroup$
JavaScript (ES6), 65 bytes
n=>'101010.1010'.replace(i=/d/g,x=>new Date(n).toJSON()[i=x-~i])
Try it online!
How?
We initialize the pointer $i$ to a non-numeric value (coerced to $0$) and then add alternately $2$ and $1$ to it to pick the relevant characters from the ISO-8601 conversion of the input timestamp.
yyyy-mm-ddThh:mm:ss.sssZ
^^ ^^ ^^ ^^ ^^
JavaScript (ES6), 66 bytes
n=>'235689.BCEF'.replace(/w/g,x=>new Date(n).toJSON()[+`0x${x}`])
Try it online!
How?
Once the input timestamp is converted in ISO-8601 format, all required characters can be accessed with a single hexadecimal digit.
yyyy-mm-ddThh:mm:ss.sssZ
↓↓ ↓↓ ↓↓ ↓↓ ↓↓
0123456789ABCDEF
$endgroup$
JavaScript (ES6), 65 bytes
n=>'101010.1010'.replace(i=/d/g,x=>new Date(n).toJSON()[i=x-~i])
Try it online!
How?
We initialize the pointer $i$ to a non-numeric value (coerced to $0$) and then add alternately $2$ and $1$ to it to pick the relevant characters from the ISO-8601 conversion of the input timestamp.
yyyy-mm-ddThh:mm:ss.sssZ
^^ ^^ ^^ ^^ ^^
JavaScript (ES6), 66 bytes
n=>'235689.BCEF'.replace(/w/g,x=>new Date(n).toJSON()[+`0x${x}`])
Try it online!
How?
Once the input timestamp is converted in ISO-8601 format, all required characters can be accessed with a single hexadecimal digit.
yyyy-mm-ddThh:mm:ss.sssZ
↓↓ ↓↓ ↓↓ ↓↓ ↓↓
0123456789ABCDEF
edited Jan 12 at 20:49
answered Jan 12 at 10:51
ArnauldArnauld
74.1k690310
74.1k690310
$begingroup$
Wow. Just, wow.
$endgroup$
– skiilaa
Jan 13 at 9:08
1
$begingroup$
64 bytes:n=>'235689.11121415'.replace(/1?w/g,x=>new Date(n).toJSON()[x])
$endgroup$
– tsh
Jan 14 at 7:02
$begingroup$
@tsh Nice! I was not expecting the decimal format to be shorter. You may want to post this as a separate answer.
$endgroup$
– Arnauld
Jan 14 at 15:45
add a comment |
$begingroup$
Wow. Just, wow.
$endgroup$
– skiilaa
Jan 13 at 9:08
1
$begingroup$
64 bytes:n=>'235689.11121415'.replace(/1?w/g,x=>new Date(n).toJSON()[x])
$endgroup$
– tsh
Jan 14 at 7:02
$begingroup$
@tsh Nice! I was not expecting the decimal format to be shorter. You may want to post this as a separate answer.
$endgroup$
– Arnauld
Jan 14 at 15:45
$begingroup$
Wow. Just, wow.
$endgroup$
– skiilaa
Jan 13 at 9:08
$begingroup$
Wow. Just, wow.
$endgroup$
– skiilaa
Jan 13 at 9:08
1
1
$begingroup$
64 bytes:
n=>'235689.11121415'.replace(/1?w/g,x=>new Date(n).toJSON()[x])
$endgroup$
– tsh
Jan 14 at 7:02
$begingroup$
64 bytes:
n=>'235689.11121415'.replace(/1?w/g,x=>new Date(n).toJSON()[x])
$endgroup$
– tsh
Jan 14 at 7:02
$begingroup$
@tsh Nice! I was not expecting the decimal format to be shorter. You may want to post this as a separate answer.
$endgroup$
– Arnauld
Jan 14 at 15:45
$begingroup$
@tsh Nice! I was not expecting the decimal format to be shorter. You may want to post this as a separate answer.
$endgroup$
– Arnauld
Jan 14 at 15:45
add a comment |
$begingroup$
Bash + coreutils, 29 bytes
date -d@${1::-3} +%y%m%d.%H%M
Try it online!
$endgroup$
add a comment |
$begingroup$
Bash + coreutils, 29 bytes
date -d@${1::-3} +%y%m%d.%H%M
Try it online!
$endgroup$
add a comment |
$begingroup$
Bash + coreutils, 29 bytes
date -d@${1::-3} +%y%m%d.%H%M
Try it online!
$endgroup$
Bash + coreutils, 29 bytes
date -d@${1::-3} +%y%m%d.%H%M
Try it online!
answered Jan 11 at 19:59
NeilNeil
80k744178
80k744178
add a comment |
add a comment |
$begingroup$
PHP, 40 32 31 bytes
-8 bytes thanks to Luis felipe
-1 byte thanks to Jo King
<?=date('ymd.hi',$argv[1]/1e3);
Try it online!
Simple naive answer. PHP's date
function takes a format string and an integer timestamp. Input from cli arguments, which is a string by default, then /1e3
because date
expects second-precise timestamps. This also coerces the string to a number.
$endgroup$
$begingroup$
Nice answer! It's a tad shorter if the language has date formatting, yes :)
$endgroup$
– skiilaa
Jan 11 at 20:03
$begingroup$
32 bytes you dont need to cast to integer since"2"/1
will cast automatically the string
$endgroup$
– Luis felipe De jesus Munoz
Jan 11 at 20:04
$begingroup$
ah of course, I added intval before realising I needed/1000
, and didn't think that I mihgt not need it afterwards :P
$endgroup$
– Skidsdev
Jan 11 at 20:08
$begingroup$
@JoKing ah nice one, thanks
$endgroup$
– Skidsdev
Jan 14 at 14:03
add a comment |
$begingroup$
PHP, 40 32 31 bytes
-8 bytes thanks to Luis felipe
-1 byte thanks to Jo King
<?=date('ymd.hi',$argv[1]/1e3);
Try it online!
Simple naive answer. PHP's date
function takes a format string and an integer timestamp. Input from cli arguments, which is a string by default, then /1e3
because date
expects second-precise timestamps. This also coerces the string to a number.
$endgroup$
$begingroup$
Nice answer! It's a tad shorter if the language has date formatting, yes :)
$endgroup$
– skiilaa
Jan 11 at 20:03
$begingroup$
32 bytes you dont need to cast to integer since"2"/1
will cast automatically the string
$endgroup$
– Luis felipe De jesus Munoz
Jan 11 at 20:04
$begingroup$
ah of course, I added intval before realising I needed/1000
, and didn't think that I mihgt not need it afterwards :P
$endgroup$
– Skidsdev
Jan 11 at 20:08
$begingroup$
@JoKing ah nice one, thanks
$endgroup$
– Skidsdev
Jan 14 at 14:03
add a comment |
$begingroup$
PHP, 40 32 31 bytes
-8 bytes thanks to Luis felipe
-1 byte thanks to Jo King
<?=date('ymd.hi',$argv[1]/1e3);
Try it online!
Simple naive answer. PHP's date
function takes a format string and an integer timestamp. Input from cli arguments, which is a string by default, then /1e3
because date
expects second-precise timestamps. This also coerces the string to a number.
$endgroup$
PHP, 40 32 31 bytes
-8 bytes thanks to Luis felipe
-1 byte thanks to Jo King
<?=date('ymd.hi',$argv[1]/1e3);
Try it online!
Simple naive answer. PHP's date
function takes a format string and an integer timestamp. Input from cli arguments, which is a string by default, then /1e3
because date
expects second-precise timestamps. This also coerces the string to a number.
edited Jan 14 at 14:02
answered Jan 11 at 20:00
SkidsdevSkidsdev
6,4262974
6,4262974
$begingroup$
Nice answer! It's a tad shorter if the language has date formatting, yes :)
$endgroup$
– skiilaa
Jan 11 at 20:03
$begingroup$
32 bytes you dont need to cast to integer since"2"/1
will cast automatically the string
$endgroup$
– Luis felipe De jesus Munoz
Jan 11 at 20:04
$begingroup$
ah of course, I added intval before realising I needed/1000
, and didn't think that I mihgt not need it afterwards :P
$endgroup$
– Skidsdev
Jan 11 at 20:08
$begingroup$
@JoKing ah nice one, thanks
$endgroup$
– Skidsdev
Jan 14 at 14:03
add a comment |
$begingroup$
Nice answer! It's a tad shorter if the language has date formatting, yes :)
$endgroup$
– skiilaa
Jan 11 at 20:03
$begingroup$
32 bytes you dont need to cast to integer since"2"/1
will cast automatically the string
$endgroup$
– Luis felipe De jesus Munoz
Jan 11 at 20:04
$begingroup$
ah of course, I added intval before realising I needed/1000
, and didn't think that I mihgt not need it afterwards :P
$endgroup$
– Skidsdev
Jan 11 at 20:08
$begingroup$
@JoKing ah nice one, thanks
$endgroup$
– Skidsdev
Jan 14 at 14:03
$begingroup$
Nice answer! It's a tad shorter if the language has date formatting, yes :)
$endgroup$
– skiilaa
Jan 11 at 20:03
$begingroup$
Nice answer! It's a tad shorter if the language has date formatting, yes :)
$endgroup$
– skiilaa
Jan 11 at 20:03
$begingroup$
32 bytes you dont need to cast to integer since
"2"/1
will cast automatically the string$endgroup$
– Luis felipe De jesus Munoz
Jan 11 at 20:04
$begingroup$
32 bytes you dont need to cast to integer since
"2"/1
will cast automatically the string$endgroup$
– Luis felipe De jesus Munoz
Jan 11 at 20:04
$begingroup$
ah of course, I added intval before realising I needed
/1000
, and didn't think that I mihgt not need it afterwards :P$endgroup$
– Skidsdev
Jan 11 at 20:08
$begingroup$
ah of course, I added intval before realising I needed
/1000
, and didn't think that I mihgt not need it afterwards :P$endgroup$
– Skidsdev
Jan 11 at 20:08
$begingroup$
@JoKing ah nice one, thanks
$endgroup$
– Skidsdev
Jan 14 at 14:03
$begingroup$
@JoKing ah nice one, thanks
$endgroup$
– Skidsdev
Jan 14 at 14:03
add a comment |
$begingroup$
MATL, 28 bytes
Thanks to @skiilaa for a correction in the output format.
864e5/719529+'YYmmDD.HHMM'XO
Try it online!
Explanation
MATL, like MATLAB, defines date/time numbers as the (possibly non-integer) number of days since time 00:00 of the reference "date" 0-Jan-0000.
Thus we take the input, divide it by 86400000 (number of milliseconds in one day), add 719529 (number of days from MATL's reference to UNIX reference), and convert to the desired format 'YYmmDD.HHMM'.
$endgroup$
add a comment |
$begingroup$
MATL, 28 bytes
Thanks to @skiilaa for a correction in the output format.
864e5/719529+'YYmmDD.HHMM'XO
Try it online!
Explanation
MATL, like MATLAB, defines date/time numbers as the (possibly non-integer) number of days since time 00:00 of the reference "date" 0-Jan-0000.
Thus we take the input, divide it by 86400000 (number of milliseconds in one day), add 719529 (number of days from MATL's reference to UNIX reference), and convert to the desired format 'YYmmDD.HHMM'.
$endgroup$
add a comment |
$begingroup$
MATL, 28 bytes
Thanks to @skiilaa for a correction in the output format.
864e5/719529+'YYmmDD.HHMM'XO
Try it online!
Explanation
MATL, like MATLAB, defines date/time numbers as the (possibly non-integer) number of days since time 00:00 of the reference "date" 0-Jan-0000.
Thus we take the input, divide it by 86400000 (number of milliseconds in one day), add 719529 (number of days from MATL's reference to UNIX reference), and convert to the desired format 'YYmmDD.HHMM'.
$endgroup$
MATL, 28 bytes
Thanks to @skiilaa for a correction in the output format.
864e5/719529+'YYmmDD.HHMM'XO
Try it online!
Explanation
MATL, like MATLAB, defines date/time numbers as the (possibly non-integer) number of days since time 00:00 of the reference "date" 0-Jan-0000.
Thus we take the input, divide it by 86400000 (number of milliseconds in one day), add 719529 (number of days from MATL's reference to UNIX reference), and convert to the desired format 'YYmmDD.HHMM'.
edited Jan 13 at 16:06
answered Jan 11 at 22:00
Luis MendoLuis Mendo
74.2k887291
74.2k887291
add a comment |
add a comment |
$begingroup$
GNU AWK, 34 33 characters
$0=strftime("%y%m%d.%H%M",$0/1e3)
(strftime()
is GNU extension, will not run in other AWK implementations.)
Thanks to:
Jo King for suggesting E-notation (-1 character)
Sampler run:
bash-4.4$ awk '$0=strftime("%y%m%d.%H%M",$0/1e3)' <<< 1547233866744
190111.2111
Try it online!
$endgroup$
$begingroup$
Thank you, @JoKing. Unfortunately E-notation is not really my friend so I always forget it.
$endgroup$
– manatwork
Jan 13 at 16:02
add a comment |
$begingroup$
GNU AWK, 34 33 characters
$0=strftime("%y%m%d.%H%M",$0/1e3)
(strftime()
is GNU extension, will not run in other AWK implementations.)
Thanks to:
Jo King for suggesting E-notation (-1 character)
Sampler run:
bash-4.4$ awk '$0=strftime("%y%m%d.%H%M",$0/1e3)' <<< 1547233866744
190111.2111
Try it online!
$endgroup$
$begingroup$
Thank you, @JoKing. Unfortunately E-notation is not really my friend so I always forget it.
$endgroup$
– manatwork
Jan 13 at 16:02
add a comment |
$begingroup$
GNU AWK, 34 33 characters
$0=strftime("%y%m%d.%H%M",$0/1e3)
(strftime()
is GNU extension, will not run in other AWK implementations.)
Thanks to:
Jo King for suggesting E-notation (-1 character)
Sampler run:
bash-4.4$ awk '$0=strftime("%y%m%d.%H%M",$0/1e3)' <<< 1547233866744
190111.2111
Try it online!
$endgroup$
GNU AWK, 34 33 characters
$0=strftime("%y%m%d.%H%M",$0/1e3)
(strftime()
is GNU extension, will not run in other AWK implementations.)
Thanks to:
Jo King for suggesting E-notation (-1 character)
Sampler run:
bash-4.4$ awk '$0=strftime("%y%m%d.%H%M",$0/1e3)' <<< 1547233866744
190111.2111
Try it online!
edited Jan 13 at 16:05
answered Jan 11 at 20:28
manatworkmanatwork
16.3k43572
16.3k43572
$begingroup$
Thank you, @JoKing. Unfortunately E-notation is not really my friend so I always forget it.
$endgroup$
– manatwork
Jan 13 at 16:02
add a comment |
$begingroup$
Thank you, @JoKing. Unfortunately E-notation is not really my friend so I always forget it.
$endgroup$
– manatwork
Jan 13 at 16:02
$begingroup$
Thank you, @JoKing. Unfortunately E-notation is not really my friend so I always forget it.
$endgroup$
– manatwork
Jan 13 at 16:02
$begingroup$
Thank you, @JoKing. Unfortunately E-notation is not really my friend so I always forget it.
$endgroup$
– manatwork
Jan 13 at 16:02
add a comment |
$begingroup$
PowerShell, 59 58 bytes
"{0:yyMMdd.HHmm}"-f(Date 1/1/1970).AddSeconds("$args"/1e3)
Try it online!
Gets the Date
of 1/1/1970
(defaults to 00:00:00am), then Add
s the appropriate number of Seconds
. Passes that to the -f
ormat operator, which correctly formats the datetime.
Probably culture-dependent. This works on TIO, which is en-us
.
-1 byte thanks to shaggy.
$endgroup$
add a comment |
$begingroup$
PowerShell, 59 58 bytes
"{0:yyMMdd.HHmm}"-f(Date 1/1/1970).AddSeconds("$args"/1e3)
Try it online!
Gets the Date
of 1/1/1970
(defaults to 00:00:00am), then Add
s the appropriate number of Seconds
. Passes that to the -f
ormat operator, which correctly formats the datetime.
Probably culture-dependent. This works on TIO, which is en-us
.
-1 byte thanks to shaggy.
$endgroup$
add a comment |
$begingroup$
PowerShell, 59 58 bytes
"{0:yyMMdd.HHmm}"-f(Date 1/1/1970).AddSeconds("$args"/1e3)
Try it online!
Gets the Date
of 1/1/1970
(defaults to 00:00:00am), then Add
s the appropriate number of Seconds
. Passes that to the -f
ormat operator, which correctly formats the datetime.
Probably culture-dependent. This works on TIO, which is en-us
.
-1 byte thanks to shaggy.
$endgroup$
PowerShell, 59 58 bytes
"{0:yyMMdd.HHmm}"-f(Date 1/1/1970).AddSeconds("$args"/1e3)
Try it online!
Gets the Date
of 1/1/1970
(defaults to 00:00:00am), then Add
s the appropriate number of Seconds
. Passes that to the -f
ormat operator, which correctly formats the datetime.
Probably culture-dependent. This works on TIO, which is en-us
.
-1 byte thanks to shaggy.
edited Jan 14 at 13:39
answered Jan 11 at 20:15
AdmBorkBorkAdmBorkBork
26.6k364229
26.6k364229
add a comment |
add a comment |
$begingroup$
Perl 6, 111 89 87 bytes
{~DateTime.new($_/Ⅿ,:formatter{"{(.year%Ⅽ,.month,.day).fmt('%02d','')}.{(.hour,.minute).fmt('%02d','')}"})}
Try it (111)
{TR/-//}o{S/..//}o{.yyyy-mm-dd~'.'~(.hour,.minute).fmt('%02d','')}o{DateTime.new($_/Ⅿ)}
Try it (89)
{TR/- //}o{S/..//}o{.yyyy-mm-dd~'.'~(.hour,.minute).fmt('%02d')}o{DateTime.new($_/Ⅿ)}
Try it (87)
Explanation:
The o
infix operator takes two functions and creates a composite function. The rightmost one gets called first, and the one to the left gets called with its result.
Basically we use 4 block lambdas to generate a single lambda.
Which is not much different to how a WhateverCode lambda like * + *
gets created.
Divide by 1000 and use that to create a DateTime object.
{DateTime.new($_/Ⅿ)} # Ⅿ is ROMAN NUMERAL ONE THOUSAND (3 bytes)
The result gets used by:
{
.yyyy-mm-dd # 2019-01-11
~ '.' ~ # str concatenation with '.'
( .hour, .minute ).fmt('%02d') # add leading 0s (returns List)
}
That leaves us with a string like 2019-01-11.19 11
We need to remove the first two digits
{S/..//}
We also need to remove -
and
{TR/- //}
$endgroup$
add a comment |
$begingroup$
Perl 6, 111 89 87 bytes
{~DateTime.new($_/Ⅿ,:formatter{"{(.year%Ⅽ,.month,.day).fmt('%02d','')}.{(.hour,.minute).fmt('%02d','')}"})}
Try it (111)
{TR/-//}o{S/..//}o{.yyyy-mm-dd~'.'~(.hour,.minute).fmt('%02d','')}o{DateTime.new($_/Ⅿ)}
Try it (89)
{TR/- //}o{S/..//}o{.yyyy-mm-dd~'.'~(.hour,.minute).fmt('%02d')}o{DateTime.new($_/Ⅿ)}
Try it (87)
Explanation:
The o
infix operator takes two functions and creates a composite function. The rightmost one gets called first, and the one to the left gets called with its result.
Basically we use 4 block lambdas to generate a single lambda.
Which is not much different to how a WhateverCode lambda like * + *
gets created.
Divide by 1000 and use that to create a DateTime object.
{DateTime.new($_/Ⅿ)} # Ⅿ is ROMAN NUMERAL ONE THOUSAND (3 bytes)
The result gets used by:
{
.yyyy-mm-dd # 2019-01-11
~ '.' ~ # str concatenation with '.'
( .hour, .minute ).fmt('%02d') # add leading 0s (returns List)
}
That leaves us with a string like 2019-01-11.19 11
We need to remove the first two digits
{S/..//}
We also need to remove -
and
{TR/- //}
$endgroup$
add a comment |
$begingroup$
Perl 6, 111 89 87 bytes
{~DateTime.new($_/Ⅿ,:formatter{"{(.year%Ⅽ,.month,.day).fmt('%02d','')}.{(.hour,.minute).fmt('%02d','')}"})}
Try it (111)
{TR/-//}o{S/..//}o{.yyyy-mm-dd~'.'~(.hour,.minute).fmt('%02d','')}o{DateTime.new($_/Ⅿ)}
Try it (89)
{TR/- //}o{S/..//}o{.yyyy-mm-dd~'.'~(.hour,.minute).fmt('%02d')}o{DateTime.new($_/Ⅿ)}
Try it (87)
Explanation:
The o
infix operator takes two functions and creates a composite function. The rightmost one gets called first, and the one to the left gets called with its result.
Basically we use 4 block lambdas to generate a single lambda.
Which is not much different to how a WhateverCode lambda like * + *
gets created.
Divide by 1000 and use that to create a DateTime object.
{DateTime.new($_/Ⅿ)} # Ⅿ is ROMAN NUMERAL ONE THOUSAND (3 bytes)
The result gets used by:
{
.yyyy-mm-dd # 2019-01-11
~ '.' ~ # str concatenation with '.'
( .hour, .minute ).fmt('%02d') # add leading 0s (returns List)
}
That leaves us with a string like 2019-01-11.19 11
We need to remove the first two digits
{S/..//}
We also need to remove -
and
{TR/- //}
$endgroup$
Perl 6, 111 89 87 bytes
{~DateTime.new($_/Ⅿ,:formatter{"{(.year%Ⅽ,.month,.day).fmt('%02d','')}.{(.hour,.minute).fmt('%02d','')}"})}
Try it (111)
{TR/-//}o{S/..//}o{.yyyy-mm-dd~'.'~(.hour,.minute).fmt('%02d','')}o{DateTime.new($_/Ⅿ)}
Try it (89)
{TR/- //}o{S/..//}o{.yyyy-mm-dd~'.'~(.hour,.minute).fmt('%02d')}o{DateTime.new($_/Ⅿ)}
Try it (87)
Explanation:
The o
infix operator takes two functions and creates a composite function. The rightmost one gets called first, and the one to the left gets called with its result.
Basically we use 4 block lambdas to generate a single lambda.
Which is not much different to how a WhateverCode lambda like * + *
gets created.
Divide by 1000 and use that to create a DateTime object.
{DateTime.new($_/Ⅿ)} # Ⅿ is ROMAN NUMERAL ONE THOUSAND (3 bytes)
The result gets used by:
{
.yyyy-mm-dd # 2019-01-11
~ '.' ~ # str concatenation with '.'
( .hour, .minute ).fmt('%02d') # add leading 0s (returns List)
}
That leaves us with a string like 2019-01-11.19 11
We need to remove the first two digits
{S/..//}
We also need to remove -
and
{TR/- //}
edited Jan 11 at 21:37
answered Jan 11 at 20:46
Brad Gilbert b2gillsBrad Gilbert b2gills
12.2k11232
12.2k11232
add a comment |
add a comment |
$begingroup$
Python 2, 64 bytes
lambda s:strftime('%y%m%d.%H%M',gmtime(s/1e3))
from time import*
Try it online!
The input is considered to be in UTC.
$endgroup$
1
$begingroup$
Just as something I've been a bit confused on, is the only reason that thelambda
comes before theimport
because it works better for TIO's header?
$endgroup$
– Neil A.
Jan 11 at 22:43
2
$begingroup$
@NeilA. Yes. The import can go either before or after, the contents of the lambda aren't checked forNameError
s before it's called.
$endgroup$
– Erik the Outgolfer
Jan 11 at 22:45
add a comment |
$begingroup$
Python 2, 64 bytes
lambda s:strftime('%y%m%d.%H%M',gmtime(s/1e3))
from time import*
Try it online!
The input is considered to be in UTC.
$endgroup$
1
$begingroup$
Just as something I've been a bit confused on, is the only reason that thelambda
comes before theimport
because it works better for TIO's header?
$endgroup$
– Neil A.
Jan 11 at 22:43
2
$begingroup$
@NeilA. Yes. The import can go either before or after, the contents of the lambda aren't checked forNameError
s before it's called.
$endgroup$
– Erik the Outgolfer
Jan 11 at 22:45
add a comment |
$begingroup$
Python 2, 64 bytes
lambda s:strftime('%y%m%d.%H%M',gmtime(s/1e3))
from time import*
Try it online!
The input is considered to be in UTC.
$endgroup$
Python 2, 64 bytes
lambda s:strftime('%y%m%d.%H%M',gmtime(s/1e3))
from time import*
Try it online!
The input is considered to be in UTC.
edited Jan 11 at 22:01
answered Jan 11 at 21:55
Erik the OutgolferErik the Outgolfer
31.6k429103
31.6k429103
1
$begingroup$
Just as something I've been a bit confused on, is the only reason that thelambda
comes before theimport
because it works better for TIO's header?
$endgroup$
– Neil A.
Jan 11 at 22:43
2
$begingroup$
@NeilA. Yes. The import can go either before or after, the contents of the lambda aren't checked forNameError
s before it's called.
$endgroup$
– Erik the Outgolfer
Jan 11 at 22:45
add a comment |
1
$begingroup$
Just as something I've been a bit confused on, is the only reason that thelambda
comes before theimport
because it works better for TIO's header?
$endgroup$
– Neil A.
Jan 11 at 22:43
2
$begingroup$
@NeilA. Yes. The import can go either before or after, the contents of the lambda aren't checked forNameError
s before it's called.
$endgroup$
– Erik the Outgolfer
Jan 11 at 22:45
1
1
$begingroup$
Just as something I've been a bit confused on, is the only reason that the
lambda
comes before the import
because it works better for TIO's header?$endgroup$
– Neil A.
Jan 11 at 22:43
$begingroup$
Just as something I've been a bit confused on, is the only reason that the
lambda
comes before the import
because it works better for TIO's header?$endgroup$
– Neil A.
Jan 11 at 22:43
2
2
$begingroup$
@NeilA. Yes. The import can go either before or after, the contents of the lambda aren't checked for
NameError
s before it's called.$endgroup$
– Erik the Outgolfer
Jan 11 at 22:45
$begingroup$
@NeilA. Yes. The import can go either before or after, the contents of the lambda aren't checked for
NameError
s before it's called.$endgroup$
– Erik the Outgolfer
Jan 11 at 22:45
add a comment |
$begingroup$
R, 58 56 bytes
format(as.POSIXct(scan()/1e3,,'1970-1-1'),'%y%m%d.%H%M')
Try it online!
$endgroup$
add a comment |
$begingroup$
R, 58 56 bytes
format(as.POSIXct(scan()/1e3,,'1970-1-1'),'%y%m%d.%H%M')
Try it online!
$endgroup$
add a comment |
$begingroup$
R, 58 56 bytes
format(as.POSIXct(scan()/1e3,,'1970-1-1'),'%y%m%d.%H%M')
Try it online!
$endgroup$
R, 58 56 bytes
format(as.POSIXct(scan()/1e3,,'1970-1-1'),'%y%m%d.%H%M')
Try it online!
edited Jan 12 at 12:03
answered Jan 12 at 11:22
digEmAlldigEmAll
3,029414
3,029414
add a comment |
add a comment |
$begingroup$
C (gcc) (32-bit, little endian), 67 bytes
f(t,s)long long t;{t/=1e3;strftime(s,12,"%y%m%d.%H%M",gmtime(&t));}
Try it online!
On an ILP64 platform, the following 55 byte version should work:
f(t,s){t/=1e3;strftime(s,12,"%y%m%d.%H%M",gmtime(&t));}
$endgroup$
$begingroup$
What's the extras
argument you're taking for?
$endgroup$
– Shaggy
Jan 12 at 14:47
1
$begingroup$
@Shaggy Thes
is for the output string.
$endgroup$
– nwellnhof
Jan 12 at 15:06
$begingroup$
It looks like you're initiating it outside the function; do we have a meta consensus that allows C to do that?
$endgroup$
– Shaggy
Jan 12 at 15:31
$begingroup$
@Shaggy I'm not sure what "consensus" means exactly but here's the relevant meta post.
$endgroup$
– nwellnhof
Jan 12 at 15:54
$begingroup$
With "32-bit,", whylong long
instead oflong
orint32_t
,int64_t
,time_t
? IAC, all shorter thanlong long
.
$endgroup$
– chux
Jan 13 at 22:23
|
show 2 more comments
$begingroup$
C (gcc) (32-bit, little endian), 67 bytes
f(t,s)long long t;{t/=1e3;strftime(s,12,"%y%m%d.%H%M",gmtime(&t));}
Try it online!
On an ILP64 platform, the following 55 byte version should work:
f(t,s){t/=1e3;strftime(s,12,"%y%m%d.%H%M",gmtime(&t));}
$endgroup$
$begingroup$
What's the extras
argument you're taking for?
$endgroup$
– Shaggy
Jan 12 at 14:47
1
$begingroup$
@Shaggy Thes
is for the output string.
$endgroup$
– nwellnhof
Jan 12 at 15:06
$begingroup$
It looks like you're initiating it outside the function; do we have a meta consensus that allows C to do that?
$endgroup$
– Shaggy
Jan 12 at 15:31
$begingroup$
@Shaggy I'm not sure what "consensus" means exactly but here's the relevant meta post.
$endgroup$
– nwellnhof
Jan 12 at 15:54
$begingroup$
With "32-bit,", whylong long
instead oflong
orint32_t
,int64_t
,time_t
? IAC, all shorter thanlong long
.
$endgroup$
– chux
Jan 13 at 22:23
|
show 2 more comments
$begingroup$
C (gcc) (32-bit, little endian), 67 bytes
f(t,s)long long t;{t/=1e3;strftime(s,12,"%y%m%d.%H%M",gmtime(&t));}
Try it online!
On an ILP64 platform, the following 55 byte version should work:
f(t,s){t/=1e3;strftime(s,12,"%y%m%d.%H%M",gmtime(&t));}
$endgroup$
C (gcc) (32-bit, little endian), 67 bytes
f(t,s)long long t;{t/=1e3;strftime(s,12,"%y%m%d.%H%M",gmtime(&t));}
Try it online!
On an ILP64 platform, the following 55 byte version should work:
f(t,s){t/=1e3;strftime(s,12,"%y%m%d.%H%M",gmtime(&t));}
edited Jan 12 at 15:08
answered Jan 12 at 14:32
nwellnhofnwellnhof
6,67511126
6,67511126
$begingroup$
What's the extras
argument you're taking for?
$endgroup$
– Shaggy
Jan 12 at 14:47
1
$begingroup$
@Shaggy Thes
is for the output string.
$endgroup$
– nwellnhof
Jan 12 at 15:06
$begingroup$
It looks like you're initiating it outside the function; do we have a meta consensus that allows C to do that?
$endgroup$
– Shaggy
Jan 12 at 15:31
$begingroup$
@Shaggy I'm not sure what "consensus" means exactly but here's the relevant meta post.
$endgroup$
– nwellnhof
Jan 12 at 15:54
$begingroup$
With "32-bit,", whylong long
instead oflong
orint32_t
,int64_t
,time_t
? IAC, all shorter thanlong long
.
$endgroup$
– chux
Jan 13 at 22:23
|
show 2 more comments
$begingroup$
What's the extras
argument you're taking for?
$endgroup$
– Shaggy
Jan 12 at 14:47
1
$begingroup$
@Shaggy Thes
is for the output string.
$endgroup$
– nwellnhof
Jan 12 at 15:06
$begingroup$
It looks like you're initiating it outside the function; do we have a meta consensus that allows C to do that?
$endgroup$
– Shaggy
Jan 12 at 15:31
$begingroup$
@Shaggy I'm not sure what "consensus" means exactly but here's the relevant meta post.
$endgroup$
– nwellnhof
Jan 12 at 15:54
$begingroup$
With "32-bit,", whylong long
instead oflong
orint32_t
,int64_t
,time_t
? IAC, all shorter thanlong long
.
$endgroup$
– chux
Jan 13 at 22:23
$begingroup$
What's the extra
s
argument you're taking for?$endgroup$
– Shaggy
Jan 12 at 14:47
$begingroup$
What's the extra
s
argument you're taking for?$endgroup$
– Shaggy
Jan 12 at 14:47
1
1
$begingroup$
@Shaggy The
s
is for the output string.$endgroup$
– nwellnhof
Jan 12 at 15:06
$begingroup$
@Shaggy The
s
is for the output string.$endgroup$
– nwellnhof
Jan 12 at 15:06
$begingroup$
It looks like you're initiating it outside the function; do we have a meta consensus that allows C to do that?
$endgroup$
– Shaggy
Jan 12 at 15:31
$begingroup$
It looks like you're initiating it outside the function; do we have a meta consensus that allows C to do that?
$endgroup$
– Shaggy
Jan 12 at 15:31
$begingroup$
@Shaggy I'm not sure what "consensus" means exactly but here's the relevant meta post.
$endgroup$
– nwellnhof
Jan 12 at 15:54
$begingroup$
@Shaggy I'm not sure what "consensus" means exactly but here's the relevant meta post.
$endgroup$
– nwellnhof
Jan 12 at 15:54
$begingroup$
With "32-bit,", why
long long
instead of long
or int32_t
, int64_t
, time_t
? IAC, all shorter than long long
.$endgroup$
– chux
Jan 13 at 22:23
$begingroup$
With "32-bit,", why
long long
instead of long
or int32_t
, int64_t
, time_t
? IAC, all shorter than long long
.$endgroup$
– chux
Jan 13 at 22:23
|
show 2 more comments
$begingroup$
Perl 6, 57 50 bytes
{TR:d/T:-/./}o{substr ~DateTime.new($_/1e3): 2,15}
Try it online!
Takes the default stringification of a Datetime, in the format yyyy-mm-ddThh:mm:ssZ
and modifies it to fit the output format. Perl 6 is in need of a date formatter method.
Explanation:
Datetime.new($_/1e3) # Create a date time
~ # Stringify it to the format yyyy-mm-ddThh:mm:ssZ
# e.g. 2019-01-11T19:11:06.744000Z
substr : 2,15 # Take the middle 15 characters
{TR:d/T /./}o # Then replace 'T' with '.'
:- # Then remove ':' and '-'
$endgroup$
add a comment |
$begingroup$
Perl 6, 57 50 bytes
{TR:d/T:-/./}o{substr ~DateTime.new($_/1e3): 2,15}
Try it online!
Takes the default stringification of a Datetime, in the format yyyy-mm-ddThh:mm:ssZ
and modifies it to fit the output format. Perl 6 is in need of a date formatter method.
Explanation:
Datetime.new($_/1e3) # Create a date time
~ # Stringify it to the format yyyy-mm-ddThh:mm:ssZ
# e.g. 2019-01-11T19:11:06.744000Z
substr : 2,15 # Take the middle 15 characters
{TR:d/T /./}o # Then replace 'T' with '.'
:- # Then remove ':' and '-'
$endgroup$
add a comment |
$begingroup$
Perl 6, 57 50 bytes
{TR:d/T:-/./}o{substr ~DateTime.new($_/1e3): 2,15}
Try it online!
Takes the default stringification of a Datetime, in the format yyyy-mm-ddThh:mm:ssZ
and modifies it to fit the output format. Perl 6 is in need of a date formatter method.
Explanation:
Datetime.new($_/1e3) # Create a date time
~ # Stringify it to the format yyyy-mm-ddThh:mm:ssZ
# e.g. 2019-01-11T19:11:06.744000Z
substr : 2,15 # Take the middle 15 characters
{TR:d/T /./}o # Then replace 'T' with '.'
:- # Then remove ':' and '-'
$endgroup$
Perl 6, 57 50 bytes
{TR:d/T:-/./}o{substr ~DateTime.new($_/1e3): 2,15}
Try it online!
Takes the default stringification of a Datetime, in the format yyyy-mm-ddThh:mm:ssZ
and modifies it to fit the output format. Perl 6 is in need of a date formatter method.
Explanation:
Datetime.new($_/1e3) # Create a date time
~ # Stringify it to the format yyyy-mm-ddThh:mm:ssZ
# e.g. 2019-01-11T19:11:06.744000Z
substr : 2,15 # Take the middle 15 characters
{TR:d/T /./}o # Then replace 'T' with '.'
:- # Then remove ':' and '-'
edited Jan 11 at 23:38
answered Jan 11 at 22:50
Jo KingJo King
21.5k248110
21.5k248110
add a comment |
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 67 61 60 bytes
n=>$"{new DateTime(1970,1,1).AddTicks(n*10000):yyMMdd.HHmm}"
For reasons unknown to me, DateTime.UnixEpoch doesn't work.
Try it online!
$endgroup$
1
$begingroup$
It seems UnixEpoch is only present in.Net Core 2.1+
$endgroup$
– digEmAll
Jan 12 at 12:19
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 67 61 60 bytes
n=>$"{new DateTime(1970,1,1).AddTicks(n*10000):yyMMdd.HHmm}"
For reasons unknown to me, DateTime.UnixEpoch doesn't work.
Try it online!
$endgroup$
1
$begingroup$
It seems UnixEpoch is only present in.Net Core 2.1+
$endgroup$
– digEmAll
Jan 12 at 12:19
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 67 61 60 bytes
n=>$"{new DateTime(1970,1,1).AddTicks(n*10000):yyMMdd.HHmm}"
For reasons unknown to me, DateTime.UnixEpoch doesn't work.
Try it online!
$endgroup$
C# (Visual C# Interactive Compiler), 67 61 60 bytes
n=>$"{new DateTime(1970,1,1).AddTicks(n*10000):yyMMdd.HHmm}"
For reasons unknown to me, DateTime.UnixEpoch doesn't work.
Try it online!
edited Jan 12 at 4:11
answered Jan 11 at 22:41
Embodiment of IgnoranceEmbodiment of Ignorance
721116
721116
1
$begingroup$
It seems UnixEpoch is only present in.Net Core 2.1+
$endgroup$
– digEmAll
Jan 12 at 12:19
add a comment |
1
$begingroup$
It seems UnixEpoch is only present in.Net Core 2.1+
$endgroup$
– digEmAll
Jan 12 at 12:19
1
1
$begingroup$
It seems UnixEpoch is only present in.Net Core 2.1+
$endgroup$
– digEmAll
Jan 12 at 12:19
$begingroup$
It seems UnixEpoch is only present in.Net Core 2.1+
$endgroup$
– digEmAll
Jan 12 at 12:19
add a comment |
$begingroup$
Javascript ES6, 76 66 bytes
x=>new Date(x).toJSON().slice(2,16).replace(/D/g,a=>a>'S'?'.':'')
Try it online
-10 bytes thanks to Shaggy!
x // timestamp
=>
new Date(x) // date object from timestamp
.toJSON() // same as .toISOString()
.slice(2,16) // cut off excess
.replace(/D/g, // match all non-digits
a // a is matched character
=>
a>'S'?'.' // if a is T (bigger than S is shorter) replace it with .
:'' // if it's not T, replace it with nothing
// this way the dashes get removed and the dot gets put in the right place
) // end of replace
$endgroup$
3
$begingroup$
You may want to wait a day or so before answering your own questions next time.
$endgroup$
– fəˈnɛtɪk
Jan 11 at 20:11
$begingroup$
71 bytes
$endgroup$
– Luis felipe De jesus Munoz
Jan 11 at 20:16
$begingroup$
Alternative 71 bytes
$endgroup$
– Shaggy
Jan 11 at 20:33
1
$begingroup$
@LuisfelipeDejesusMunoz, that's different enough for you to post yourself.
$endgroup$
– Shaggy
Jan 11 at 21:49
$begingroup$
@LuisfelipeDejesusMunoz 66 bytes to tie you with Arnauld.
$endgroup$
– Shaggy
Jan 12 at 13:50
add a comment |
$begingroup$
Javascript ES6, 76 66 bytes
x=>new Date(x).toJSON().slice(2,16).replace(/D/g,a=>a>'S'?'.':'')
Try it online
-10 bytes thanks to Shaggy!
x // timestamp
=>
new Date(x) // date object from timestamp
.toJSON() // same as .toISOString()
.slice(2,16) // cut off excess
.replace(/D/g, // match all non-digits
a // a is matched character
=>
a>'S'?'.' // if a is T (bigger than S is shorter) replace it with .
:'' // if it's not T, replace it with nothing
// this way the dashes get removed and the dot gets put in the right place
) // end of replace
$endgroup$
3
$begingroup$
You may want to wait a day or so before answering your own questions next time.
$endgroup$
– fəˈnɛtɪk
Jan 11 at 20:11
$begingroup$
71 bytes
$endgroup$
– Luis felipe De jesus Munoz
Jan 11 at 20:16
$begingroup$
Alternative 71 bytes
$endgroup$
– Shaggy
Jan 11 at 20:33
1
$begingroup$
@LuisfelipeDejesusMunoz, that's different enough for you to post yourself.
$endgroup$
– Shaggy
Jan 11 at 21:49
$begingroup$
@LuisfelipeDejesusMunoz 66 bytes to tie you with Arnauld.
$endgroup$
– Shaggy
Jan 12 at 13:50
add a comment |
$begingroup$
Javascript ES6, 76 66 bytes
x=>new Date(x).toJSON().slice(2,16).replace(/D/g,a=>a>'S'?'.':'')
Try it online
-10 bytes thanks to Shaggy!
x // timestamp
=>
new Date(x) // date object from timestamp
.toJSON() // same as .toISOString()
.slice(2,16) // cut off excess
.replace(/D/g, // match all non-digits
a // a is matched character
=>
a>'S'?'.' // if a is T (bigger than S is shorter) replace it with .
:'' // if it's not T, replace it with nothing
// this way the dashes get removed and the dot gets put in the right place
) // end of replace
$endgroup$
Javascript ES6, 76 66 bytes
x=>new Date(x).toJSON().slice(2,16).replace(/D/g,a=>a>'S'?'.':'')
Try it online
-10 bytes thanks to Shaggy!
x // timestamp
=>
new Date(x) // date object from timestamp
.toJSON() // same as .toISOString()
.slice(2,16) // cut off excess
.replace(/D/g, // match all non-digits
a // a is matched character
=>
a>'S'?'.' // if a is T (bigger than S is shorter) replace it with .
:'' // if it's not T, replace it with nothing
// this way the dashes get removed and the dot gets put in the right place
) // end of replace
edited Jan 12 at 18:38
answered Jan 11 at 19:27
skiilaaskiilaa
1638
1638
3
$begingroup$
You may want to wait a day or so before answering your own questions next time.
$endgroup$
– fəˈnɛtɪk
Jan 11 at 20:11
$begingroup$
71 bytes
$endgroup$
– Luis felipe De jesus Munoz
Jan 11 at 20:16
$begingroup$
Alternative 71 bytes
$endgroup$
– Shaggy
Jan 11 at 20:33
1
$begingroup$
@LuisfelipeDejesusMunoz, that's different enough for you to post yourself.
$endgroup$
– Shaggy
Jan 11 at 21:49
$begingroup$
@LuisfelipeDejesusMunoz 66 bytes to tie you with Arnauld.
$endgroup$
– Shaggy
Jan 12 at 13:50
add a comment |
3
$begingroup$
You may want to wait a day or so before answering your own questions next time.
$endgroup$
– fəˈnɛtɪk
Jan 11 at 20:11
$begingroup$
71 bytes
$endgroup$
– Luis felipe De jesus Munoz
Jan 11 at 20:16
$begingroup$
Alternative 71 bytes
$endgroup$
– Shaggy
Jan 11 at 20:33
1
$begingroup$
@LuisfelipeDejesusMunoz, that's different enough for you to post yourself.
$endgroup$
– Shaggy
Jan 11 at 21:49
$begingroup$
@LuisfelipeDejesusMunoz 66 bytes to tie you with Arnauld.
$endgroup$
– Shaggy
Jan 12 at 13:50
3
3
$begingroup$
You may want to wait a day or so before answering your own questions next time.
$endgroup$
– fəˈnɛtɪk
Jan 11 at 20:11
$begingroup$
You may want to wait a day or so before answering your own questions next time.
$endgroup$
– fəˈnɛtɪk
Jan 11 at 20:11
$begingroup$
71 bytes
$endgroup$
– Luis felipe De jesus Munoz
Jan 11 at 20:16
$begingroup$
71 bytes
$endgroup$
– Luis felipe De jesus Munoz
Jan 11 at 20:16
$begingroup$
Alternative 71 bytes
$endgroup$
– Shaggy
Jan 11 at 20:33
$begingroup$
Alternative 71 bytes
$endgroup$
– Shaggy
Jan 11 at 20:33
1
1
$begingroup$
@LuisfelipeDejesusMunoz, that's different enough for you to post yourself.
$endgroup$
– Shaggy
Jan 11 at 21:49
$begingroup$
@LuisfelipeDejesusMunoz, that's different enough for you to post yourself.
$endgroup$
– Shaggy
Jan 11 at 21:49
$begingroup$
@LuisfelipeDejesusMunoz 66 bytes to tie you with Arnauld.
$endgroup$
– Shaggy
Jan 12 at 13:50
$begingroup$
@LuisfelipeDejesusMunoz 66 bytes to tie you with Arnauld.
$endgroup$
– Shaggy
Jan 12 at 13:50
add a comment |
$begingroup$
C (clang), 117 111 bytes
Thanks to @chux and @ceilingcat for the suggestions.
#import<time.h>
*l;f(long t){t/=1e3;printf("%02d%02d%02d.%02d%02d",5[l=gmtime(&t)]%100,l[4]+1,l[3],l[2],l[1]);}
Try it online!
$endgroup$
$begingroup$
gmtime
is short thanlocaltime
$endgroup$
– chux
Jan 13 at 22:08
add a comment |
$begingroup$
C (clang), 117 111 bytes
Thanks to @chux and @ceilingcat for the suggestions.
#import<time.h>
*l;f(long t){t/=1e3;printf("%02d%02d%02d.%02d%02d",5[l=gmtime(&t)]%100,l[4]+1,l[3],l[2],l[1]);}
Try it online!
$endgroup$
$begingroup$
gmtime
is short thanlocaltime
$endgroup$
– chux
Jan 13 at 22:08
add a comment |
$begingroup$
C (clang), 117 111 bytes
Thanks to @chux and @ceilingcat for the suggestions.
#import<time.h>
*l;f(long t){t/=1e3;printf("%02d%02d%02d.%02d%02d",5[l=gmtime(&t)]%100,l[4]+1,l[3],l[2],l[1]);}
Try it online!
$endgroup$
C (clang), 117 111 bytes
Thanks to @chux and @ceilingcat for the suggestions.
#import<time.h>
*l;f(long t){t/=1e3;printf("%02d%02d%02d.%02d%02d",5[l=gmtime(&t)]%100,l[4]+1,l[3],l[2],l[1]);}
Try it online!
edited Jan 14 at 12:15
answered Jan 12 at 3:26
ErikFErikF
1,29917
1,29917
$begingroup$
gmtime
is short thanlocaltime
$endgroup$
– chux
Jan 13 at 22:08
add a comment |
$begingroup$
gmtime
is short thanlocaltime
$endgroup$
– chux
Jan 13 at 22:08
$begingroup$
gmtime
is short than localtime
$endgroup$
– chux
Jan 13 at 22:08
$begingroup$
gmtime
is short than localtime
$endgroup$
– chux
Jan 13 at 22:08
add a comment |
$begingroup$
Twig, 25 characters
{{d[:-3]|date('ymd.hi')}}
This is a template. Call it by including it and pass the Unix time as parameter d.
Sample usage:
{{include('datetime.twig', {'d': 1547233866744})}}
Try it on TwigFiddle
$endgroup$
add a comment |
$begingroup$
Twig, 25 characters
{{d[:-3]|date('ymd.hi')}}
This is a template. Call it by including it and pass the Unix time as parameter d.
Sample usage:
{{include('datetime.twig', {'d': 1547233866744})}}
Try it on TwigFiddle
$endgroup$
add a comment |
$begingroup$
Twig, 25 characters
{{d[:-3]|date('ymd.hi')}}
This is a template. Call it by including it and pass the Unix time as parameter d.
Sample usage:
{{include('datetime.twig', {'d': 1547233866744})}}
Try it on TwigFiddle
$endgroup$
Twig, 25 characters
{{d[:-3]|date('ymd.hi')}}
This is a template. Call it by including it and pass the Unix time as parameter d.
Sample usage:
{{include('datetime.twig', {'d': 1547233866744})}}
Try it on TwigFiddle
answered Jan 14 at 13:13
manatworkmanatwork
16.3k43572
16.3k43572
add a comment |
add a comment |
$begingroup$
JavaScript, 64 bytes
n=>'2356891911121415'.replace(/1?./g,x=>new Date(n).toJSON()[x])
Try it online!
$endgroup$
$begingroup$
aw, so close
$endgroup$
– ASCII-only
Jan 15 at 5:47
$begingroup$
also 64
$endgroup$
– ASCII-only
Jan 15 at 5:48
add a comment |
$begingroup$
JavaScript, 64 bytes
n=>'2356891911121415'.replace(/1?./g,x=>new Date(n).toJSON()[x])
Try it online!
$endgroup$
$begingroup$
aw, so close
$endgroup$
– ASCII-only
Jan 15 at 5:47
$begingroup$
also 64
$endgroup$
– ASCII-only
Jan 15 at 5:48
add a comment |
$begingroup$
JavaScript, 64 bytes
n=>'2356891911121415'.replace(/1?./g,x=>new Date(n).toJSON()[x])
Try it online!
$endgroup$
JavaScript, 64 bytes
n=>'2356891911121415'.replace(/1?./g,x=>new Date(n).toJSON()[x])
Try it online!
answered Jan 15 at 2:36
tshtsh
8,61511547
8,61511547
$begingroup$
aw, so close
$endgroup$
– ASCII-only
Jan 15 at 5:47
$begingroup$
also 64
$endgroup$
– ASCII-only
Jan 15 at 5:48
add a comment |
$begingroup$
aw, so close
$endgroup$
– ASCII-only
Jan 15 at 5:47
$begingroup$
also 64
$endgroup$
– ASCII-only
Jan 15 at 5:48
$begingroup$
aw, so close
$endgroup$
– ASCII-only
Jan 15 at 5:47
$begingroup$
aw, so close
$endgroup$
– ASCII-only
Jan 15 at 5:47
$begingroup$
also 64
$endgroup$
– ASCII-only
Jan 15 at 5:48
$begingroup$
also 64
$endgroup$
– ASCII-only
Jan 15 at 5:48
add a comment |
$begingroup$
jq, 33 characters
(30 characters code + 3 characters command line option)
./1000|strftime("%y%m%d.%H%M")
Sample run:
bash-4.4$ jq -r './1000|strftime("%y%m%d.%H%M")' <<< 1547233866744
190111.1911
Try it online!
$endgroup$
3
$begingroup$
You don't need to count command-line flags anymore.
$endgroup$
– AdmBorkBork
Jan 11 at 20:28
$begingroup$
Oops. Good to know. Thank you @AdmBorkBork.
$endgroup$
– manatwork
Jan 11 at 20:36
$begingroup$
1000
->1e3
$endgroup$
– Shaggy
Jan 14 at 20:16
add a comment |
$begingroup$
jq, 33 characters
(30 characters code + 3 characters command line option)
./1000|strftime("%y%m%d.%H%M")
Sample run:
bash-4.4$ jq -r './1000|strftime("%y%m%d.%H%M")' <<< 1547233866744
190111.1911
Try it online!
$endgroup$
3
$begingroup$
You don't need to count command-line flags anymore.
$endgroup$
– AdmBorkBork
Jan 11 at 20:28
$begingroup$
Oops. Good to know. Thank you @AdmBorkBork.
$endgroup$
– manatwork
Jan 11 at 20:36
$begingroup$
1000
->1e3
$endgroup$
– Shaggy
Jan 14 at 20:16
add a comment |
$begingroup$
jq, 33 characters
(30 characters code + 3 characters command line option)
./1000|strftime("%y%m%d.%H%M")
Sample run:
bash-4.4$ jq -r './1000|strftime("%y%m%d.%H%M")' <<< 1547233866744
190111.1911
Try it online!
$endgroup$
jq, 33 characters
(30 characters code + 3 characters command line option)
./1000|strftime("%y%m%d.%H%M")
Sample run:
bash-4.4$ jq -r './1000|strftime("%y%m%d.%H%M")' <<< 1547233866744
190111.1911
Try it online!
answered Jan 11 at 20:20
manatworkmanatwork
16.3k43572
16.3k43572
3
$begingroup$
You don't need to count command-line flags anymore.
$endgroup$
– AdmBorkBork
Jan 11 at 20:28
$begingroup$
Oops. Good to know. Thank you @AdmBorkBork.
$endgroup$
– manatwork
Jan 11 at 20:36
$begingroup$
1000
->1e3
$endgroup$
– Shaggy
Jan 14 at 20:16
add a comment |
3
$begingroup$
You don't need to count command-line flags anymore.
$endgroup$
– AdmBorkBork
Jan 11 at 20:28
$begingroup$
Oops. Good to know. Thank you @AdmBorkBork.
$endgroup$
– manatwork
Jan 11 at 20:36
$begingroup$
1000
->1e3
$endgroup$
– Shaggy
Jan 14 at 20:16
3
3
$begingroup$
You don't need to count command-line flags anymore.
$endgroup$
– AdmBorkBork
Jan 11 at 20:28
$begingroup$
You don't need to count command-line flags anymore.
$endgroup$
– AdmBorkBork
Jan 11 at 20:28
$begingroup$
Oops. Good to know. Thank you @AdmBorkBork.
$endgroup$
– manatwork
Jan 11 at 20:36
$begingroup$
Oops. Good to know. Thank you @AdmBorkBork.
$endgroup$
– manatwork
Jan 11 at 20:36
$begingroup$
1000
-> 1e3
$endgroup$
– Shaggy
Jan 14 at 20:16
$begingroup$
1000
-> 1e3
$endgroup$
– Shaggy
Jan 14 at 20:16
add a comment |
$begingroup$
ksh, 36 bytes
printf "%(%y%m%d.%H%M)T" $(($1/1e3))
Try it online!
Thanks to Jo King for 15 bytes saved
$endgroup$
$begingroup$
The same in Bash would be just 35 characters: Try it online!
$endgroup$
– manatwork
Jan 13 at 15:25
add a comment |
$begingroup$
ksh, 36 bytes
printf "%(%y%m%d.%H%M)T" $(($1/1e3))
Try it online!
Thanks to Jo King for 15 bytes saved
$endgroup$
$begingroup$
The same in Bash would be just 35 characters: Try it online!
$endgroup$
– manatwork
Jan 13 at 15:25
add a comment |
$begingroup$
ksh, 36 bytes
printf "%(%y%m%d.%H%M)T" $(($1/1e3))
Try it online!
Thanks to Jo King for 15 bytes saved
$endgroup$
ksh, 36 bytes
printf "%(%y%m%d.%H%M)T" $(($1/1e3))
Try it online!
Thanks to Jo King for 15 bytes saved
edited Jan 12 at 2:55
answered Jan 12 at 1:56
Sergiy KolodyazhnyySergiy Kolodyazhnyy
331110
331110
$begingroup$
The same in Bash would be just 35 characters: Try it online!
$endgroup$
– manatwork
Jan 13 at 15:25
add a comment |
$begingroup$
The same in Bash would be just 35 characters: Try it online!
$endgroup$
– manatwork
Jan 13 at 15:25
$begingroup$
The same in Bash would be just 35 characters: Try it online!
$endgroup$
– manatwork
Jan 13 at 15:25
$begingroup$
The same in Bash would be just 35 characters: Try it online!
$endgroup$
– manatwork
Jan 13 at 15:25
add a comment |
$begingroup$
MediaWiki, 46 bytes
{{#time:ymd.Hi|@{{#expr:floor({{{1}}}/1e3)}}}}
$endgroup$
add a comment |
$begingroup$
MediaWiki, 46 bytes
{{#time:ymd.Hi|@{{#expr:floor({{{1}}}/1e3)}}}}
$endgroup$
add a comment |
$begingroup$
MediaWiki, 46 bytes
{{#time:ymd.Hi|@{{#expr:floor({{{1}}}/1e3)}}}}
$endgroup$
MediaWiki, 46 bytes
{{#time:ymd.Hi|@{{#expr:floor({{{1}}}/1e3)}}}}
answered Jan 13 at 11:19
tshtsh
8,61511547
8,61511547
add a comment |
add a comment |
$begingroup$
Java 8, 78 bytes
n->new java.text.SimpleDateFormat("yyMMdd.HHmm").format(new java.util.Date(n))
Try it online.
Explanation:
n-> // Method with long parameter and String return-type
new java.text.SimpleDateFormat("yyMMdd.HHmm")
// Create the formatter
.format( // Format the date to a String in this format and return it:
new java.util.Date( // Create a new Date
n)) // With the input-long as timestamp
$endgroup$
add a comment |
$begingroup$
Java 8, 78 bytes
n->new java.text.SimpleDateFormat("yyMMdd.HHmm").format(new java.util.Date(n))
Try it online.
Explanation:
n-> // Method with long parameter and String return-type
new java.text.SimpleDateFormat("yyMMdd.HHmm")
// Create the formatter
.format( // Format the date to a String in this format and return it:
new java.util.Date( // Create a new Date
n)) // With the input-long as timestamp
$endgroup$
add a comment |
$begingroup$
Java 8, 78 bytes
n->new java.text.SimpleDateFormat("yyMMdd.HHmm").format(new java.util.Date(n))
Try it online.
Explanation:
n-> // Method with long parameter and String return-type
new java.text.SimpleDateFormat("yyMMdd.HHmm")
// Create the formatter
.format( // Format the date to a String in this format and return it:
new java.util.Date( // Create a new Date
n)) // With the input-long as timestamp
$endgroup$
Java 8, 78 bytes
n->new java.text.SimpleDateFormat("yyMMdd.HHmm").format(new java.util.Date(n))
Try it online.
Explanation:
n-> // Method with long parameter and String return-type
new java.text.SimpleDateFormat("yyMMdd.HHmm")
// Create the formatter
.format( // Format the date to a String in this format and return it:
new java.util.Date( // Create a new Date
n)) // With the input-long as timestamp
answered Jan 15 at 8:24
Kevin CruijssenKevin Cruijssen
36.8k555193
36.8k555193
add a comment |
add a comment |
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f178662%2funix-timestamp-to-datetime-string%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
$begingroup$
Welcome to PPCG! Nice challenge, but there are a few clarifications to be made. To make the challenge self-contained, you should probably explain what the Unix epoch is. Additionally, what should be done with leap seconds? What should be done with the Year 2038 problem?
$endgroup$
– AdmBorkBork
Jan 11 at 19:43
1
$begingroup$
@AdmBorkBork Edited the post to explain what the Unix epoch is. Leap second implementation doesn't matter, since the output string is not second-precise. The Year 2038 problem doesn't currently matter since it could be a limitation of the running device or the chosen programming language.
$endgroup$
– skiilaa
Jan 11 at 19:50
1
$begingroup$
Does the timezone matter?
$endgroup$
– Erik the Outgolfer
Jan 11 at 21:52
$begingroup$
I take it the year is represented by a two digit number?
$endgroup$
– Embodiment of Ignorance
Jan 11 at 22:22
1
$begingroup$
@FabianRöling timezones don't matter.
$endgroup$
– skiilaa
Jan 12 at 18:04