Unix timestamp to datetime string
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
New contributor
|
show 9 more comments
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
New contributor
2
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?
– AdmBorkBork
2 days ago
1
@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.
– skiilaa
2 days ago
1
Does the timezone matter?
– Erik the Outgolfer
2 days ago
I take it the year is represented by a two digit number?
– Embodiment of Ignorance
2 days ago
1
@FabianRöling timezones don't matter.
– skiilaa
yesterday
|
show 9 more comments
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
New contributor
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
New contributor
New contributor
edited yesterday
Community♦
1
1
New contributor
asked 2 days ago
skiilaaskiilaa
1637
1637
New contributor
New contributor
2
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?
– AdmBorkBork
2 days ago
1
@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.
– skiilaa
2 days ago
1
Does the timezone matter?
– Erik the Outgolfer
2 days ago
I take it the year is represented by a two digit number?
– Embodiment of Ignorance
2 days ago
1
@FabianRöling timezones don't matter.
– skiilaa
yesterday
|
show 9 more comments
2
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?
– AdmBorkBork
2 days ago
1
@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.
– skiilaa
2 days ago
1
Does the timezone matter?
– Erik the Outgolfer
2 days ago
I take it the year is represented by a two digit number?
– Embodiment of Ignorance
2 days ago
1
@FabianRöling timezones don't matter.
– skiilaa
yesterday
2
2
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?
– AdmBorkBork
2 days ago
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?
– AdmBorkBork
2 days ago
1
1
@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.
– skiilaa
2 days ago
@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.
– skiilaa
2 days ago
1
1
Does the timezone matter?
– Erik the Outgolfer
2 days ago
Does the timezone matter?
– Erik the Outgolfer
2 days ago
I take it the year is represented by a two digit number?
– Embodiment of Ignorance
2 days ago
I take it the year is represented by a two digit number?
– Embodiment of Ignorance
2 days ago
1
1
@FabianRöling timezones don't matter.
– skiilaa
yesterday
@FabianRöling timezones don't matter.
– skiilaa
yesterday
|
show 9 more comments
19 Answers
19
active
oldest
votes
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.
for 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.
add a comment |
Bash + coreutils, 29 bytes
date -d@${1::-3} +%y%m%d.%H%M
Try it online!
add a comment |
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
Wow. Just, wow.
– skiilaa
yesterday
1
64 bytes:n=>'235689.11121415'.replace(/1?w/g,x=>new Date(n).toJSON()[x])
– tsh
7 hours ago
add a comment |
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.
Nice answer! It's a tad shorter if the language has date formatting, yes :)
– skiilaa
2 days ago
32 bytes you dont need to cast to integer since"2"/1
will cast automatically the string
– Luis felipe De jesus Munoz
2 days ago
ah of course, I added intval before realising I needed/1000
, and didn't think that I mihgt not need it afterwards :P
– Skidsdev
2 days ago
4
1000
=>1e3
– Jo King
2 days ago
@JoKing ah nice one, thanks
– Skidsdev
33 mins ago
add a comment |
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'.
This is incorrect. The correct output would be 'YYmmDD.HHMM'
– skiilaa
yesterday
1
@skiilaa Thanks! Corrected now
– Luis Mendo
yesterday
add a comment |
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!
Thank you, @JoKing. Unfortunately E-notation is not really my friend so I always forget it.
– manatwork
22 hours ago
add a comment |
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/- //}
add a comment |
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));}
What's the extras
argument you're taking for?
– Shaggy
yesterday
1
@Shaggy Thes
is for the output string.
– nwellnhof
yesterday
It looks like you're initiating it outside the function; do we have a meta consensus that allows C to do that?
– Shaggy
yesterday
@Shaggy I'm not sure what "consensus" means exactly but here's the relevant meta post.
– nwellnhof
yesterday
With "32-bit,", whylong long
instead oflong
orint32_t
,int64_t
,time_t
? IAC, all shorter thanlong long
.
– chux
16 hours ago
|
show 2 more comments
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.
1000
->1e3
– Shaggy
yesterday
@Shaggy Of course, thanks!
– AdmBorkBork
56 mins ago
add a comment |
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.
1
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?
– Neil A.
2 days ago
2
@NeilA. Yes. The import can go either before or after, the contents of the lambda aren't checked forNameError
s before it's called.
– Erik the Outgolfer
2 days ago
add a comment |
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 '-'
add a comment |
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!
1
It seems UnixEpoch is only present in.Net Core 2.1+
– digEmAll
2 days ago
add a comment |
R, 58 56 bytes
format(as.POSIXct(scan()/1e3,,'1970-1-1'),'%y%m%d.%H%M')
Try it online!
add a comment |
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
New contributor
3
You may want to wait a day or so before answering your own questions next time.
– fəˈnɛtɪk
2 days ago
71 bytes
– Luis felipe De jesus Munoz
2 days ago
Alternative 71 bytes
– Shaggy
2 days ago
1
@LuisfelipeDejesusMunoz, that's different enough for you to post yourself.
– Shaggy
2 days ago
@LuisfelipeDejesusMunoz 66 bytes to tie you with Arnauld.
– Shaggy
2 days ago
add a comment |
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!
gmtime
is short thanlocaltime
– chux
16 hours ago
Suggestprintf("%02d%02d%02d.%02d%02d",5[l=gmtime(&t)]%100
instead ofl=gmtime(&t);printf("%02d%02d%02d.%02d%02d",l[5]%100
– ceilingcat
4 hours ago
add a comment |
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!
2
You don't need to count command-line flags anymore.
– AdmBorkBork
2 days ago
Oops. Good to know. Thank you @AdmBorkBork.
– manatwork
2 days ago
add a comment |
ksh, 36 bytes
printf "%(%y%m%d.%H%M)T" $(($1/1e3))
Try it online!
Thanks to Jo King for 15 bytes saved
The same in Bash would be just 35 characters: Try it online!
– manatwork
23 hours ago
add a comment |
MediaWiki, 46 bytes
{{#time:ymd.Hi|@{{#expr:floor({{{1}}}/1e3)}}}}
add a comment |
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
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
});
}
});
skiilaa is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
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
19 Answers
19
active
oldest
votes
19 Answers
19
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
for 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.
add a comment |
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.
for 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.
add a comment |
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.
for 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.
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.
for 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 3 hours ago
answered 2 days ago
ShaggyShaggy
19.2k21666
19.2k21666
add a comment |
add a comment |
Bash + coreutils, 29 bytes
date -d@${1::-3} +%y%m%d.%H%M
Try it online!
add a comment |
Bash + coreutils, 29 bytes
date -d@${1::-3} +%y%m%d.%H%M
Try it online!
add a comment |
Bash + coreutils, 29 bytes
date -d@${1::-3} +%y%m%d.%H%M
Try it online!
Bash + coreutils, 29 bytes
date -d@${1::-3} +%y%m%d.%H%M
Try it online!
answered 2 days ago
NeilNeil
79.7k744177
79.7k744177
add a comment |
add a comment |
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
Wow. Just, wow.
– skiilaa
yesterday
1
64 bytes:n=>'235689.11121415'.replace(/1?w/g,x=>new Date(n).toJSON()[x])
– tsh
7 hours ago
add a comment |
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
Wow. Just, wow.
– skiilaa
yesterday
1
64 bytes:n=>'235689.11121415'.replace(/1?w/g,x=>new Date(n).toJSON()[x])
– tsh
7 hours ago
add a comment |
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
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 yesterday
answered 2 days ago
ArnauldArnauld
73.1k689307
73.1k689307
Wow. Just, wow.
– skiilaa
yesterday
1
64 bytes:n=>'235689.11121415'.replace(/1?w/g,x=>new Date(n).toJSON()[x])
– tsh
7 hours ago
add a comment |
Wow. Just, wow.
– skiilaa
yesterday
1
64 bytes:n=>'235689.11121415'.replace(/1?w/g,x=>new Date(n).toJSON()[x])
– tsh
7 hours ago
Wow. Just, wow.
– skiilaa
yesterday
Wow. Just, wow.
– skiilaa
yesterday
1
1
64 bytes:
n=>'235689.11121415'.replace(/1?w/g,x=>new Date(n).toJSON()[x])
– tsh
7 hours ago
64 bytes:
n=>'235689.11121415'.replace(/1?w/g,x=>new Date(n).toJSON()[x])
– tsh
7 hours ago
add a comment |
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.
Nice answer! It's a tad shorter if the language has date formatting, yes :)
– skiilaa
2 days ago
32 bytes you dont need to cast to integer since"2"/1
will cast automatically the string
– Luis felipe De jesus Munoz
2 days ago
ah of course, I added intval before realising I needed/1000
, and didn't think that I mihgt not need it afterwards :P
– Skidsdev
2 days ago
4
1000
=>1e3
– Jo King
2 days ago
@JoKing ah nice one, thanks
– Skidsdev
33 mins ago
add a comment |
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.
Nice answer! It's a tad shorter if the language has date formatting, yes :)
– skiilaa
2 days ago
32 bytes you dont need to cast to integer since"2"/1
will cast automatically the string
– Luis felipe De jesus Munoz
2 days ago
ah of course, I added intval before realising I needed/1000
, and didn't think that I mihgt not need it afterwards :P
– Skidsdev
2 days ago
4
1000
=>1e3
– Jo King
2 days ago
@JoKing ah nice one, thanks
– Skidsdev
33 mins ago
add a comment |
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.
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 33 mins ago
answered 2 days ago
SkidsdevSkidsdev
6,4012974
6,4012974
Nice answer! It's a tad shorter if the language has date formatting, yes :)
– skiilaa
2 days ago
32 bytes you dont need to cast to integer since"2"/1
will cast automatically the string
– Luis felipe De jesus Munoz
2 days ago
ah of course, I added intval before realising I needed/1000
, and didn't think that I mihgt not need it afterwards :P
– Skidsdev
2 days ago
4
1000
=>1e3
– Jo King
2 days ago
@JoKing ah nice one, thanks
– Skidsdev
33 mins ago
add a comment |
Nice answer! It's a tad shorter if the language has date formatting, yes :)
– skiilaa
2 days ago
32 bytes you dont need to cast to integer since"2"/1
will cast automatically the string
– Luis felipe De jesus Munoz
2 days ago
ah of course, I added intval before realising I needed/1000
, and didn't think that I mihgt not need it afterwards :P
– Skidsdev
2 days ago
4
1000
=>1e3
– Jo King
2 days ago
@JoKing ah nice one, thanks
– Skidsdev
33 mins ago
Nice answer! It's a tad shorter if the language has date formatting, yes :)
– skiilaa
2 days ago
Nice answer! It's a tad shorter if the language has date formatting, yes :)
– skiilaa
2 days ago
32 bytes you dont need to cast to integer since
"2"/1
will cast automatically the string– Luis felipe De jesus Munoz
2 days ago
32 bytes you dont need to cast to integer since
"2"/1
will cast automatically the string– Luis felipe De jesus Munoz
2 days ago
ah of course, I added intval before realising I needed
/1000
, and didn't think that I mihgt not need it afterwards :P– Skidsdev
2 days ago
ah of course, I added intval before realising I needed
/1000
, and didn't think that I mihgt not need it afterwards :P– Skidsdev
2 days ago
4
4
1000
=> 1e3
– Jo King
2 days ago
1000
=> 1e3
– Jo King
2 days ago
@JoKing ah nice one, thanks
– Skidsdev
33 mins ago
@JoKing ah nice one, thanks
– Skidsdev
33 mins ago
add a comment |
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'.
This is incorrect. The correct output would be 'YYmmDD.HHMM'
– skiilaa
yesterday
1
@skiilaa Thanks! Corrected now
– Luis Mendo
yesterday
add a comment |
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'.
This is incorrect. The correct output would be 'YYmmDD.HHMM'
– skiilaa
yesterday
1
@skiilaa Thanks! Corrected now
– Luis Mendo
yesterday
add a comment |
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'.
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 22 hours ago
answered 2 days ago
Luis MendoLuis Mendo
74.1k886291
74.1k886291
This is incorrect. The correct output would be 'YYmmDD.HHMM'
– skiilaa
yesterday
1
@skiilaa Thanks! Corrected now
– Luis Mendo
yesterday
add a comment |
This is incorrect. The correct output would be 'YYmmDD.HHMM'
– skiilaa
yesterday
1
@skiilaa Thanks! Corrected now
– Luis Mendo
yesterday
This is incorrect. The correct output would be 'YYmmDD.HHMM'
– skiilaa
yesterday
This is incorrect. The correct output would be 'YYmmDD.HHMM'
– skiilaa
yesterday
1
1
@skiilaa Thanks! Corrected now
– Luis Mendo
yesterday
@skiilaa Thanks! Corrected now
– Luis Mendo
yesterday
add a comment |
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!
Thank you, @JoKing. Unfortunately E-notation is not really my friend so I always forget it.
– manatwork
22 hours ago
add a comment |
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!
Thank you, @JoKing. Unfortunately E-notation is not really my friend so I always forget it.
– manatwork
22 hours ago
add a comment |
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!
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 22 hours ago
answered 2 days ago
manatworkmanatwork
16.3k43572
16.3k43572
Thank you, @JoKing. Unfortunately E-notation is not really my friend so I always forget it.
– manatwork
22 hours ago
add a comment |
Thank you, @JoKing. Unfortunately E-notation is not really my friend so I always forget it.
– manatwork
22 hours ago
Thank you, @JoKing. Unfortunately E-notation is not really my friend so I always forget it.
– manatwork
22 hours ago
Thank you, @JoKing. Unfortunately E-notation is not really my friend so I always forget it.
– manatwork
22 hours ago
add a comment |
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/- //}
add a comment |
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/- //}
add a comment |
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/- //}
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 2 days ago
answered 2 days ago
Brad Gilbert b2gillsBrad Gilbert b2gills
12.2k11232
12.2k11232
add a comment |
add a comment |
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));}
What's the extras
argument you're taking for?
– Shaggy
yesterday
1
@Shaggy Thes
is for the output string.
– nwellnhof
yesterday
It looks like you're initiating it outside the function; do we have a meta consensus that allows C to do that?
– Shaggy
yesterday
@Shaggy I'm not sure what "consensus" means exactly but here's the relevant meta post.
– nwellnhof
yesterday
With "32-bit,", whylong long
instead oflong
orint32_t
,int64_t
,time_t
? IAC, all shorter thanlong long
.
– chux
16 hours ago
|
show 2 more comments
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));}
What's the extras
argument you're taking for?
– Shaggy
yesterday
1
@Shaggy Thes
is for the output string.
– nwellnhof
yesterday
It looks like you're initiating it outside the function; do we have a meta consensus that allows C to do that?
– Shaggy
yesterday
@Shaggy I'm not sure what "consensus" means exactly but here's the relevant meta post.
– nwellnhof
yesterday
With "32-bit,", whylong long
instead oflong
orint32_t
,int64_t
,time_t
? IAC, all shorter thanlong long
.
– chux
16 hours ago
|
show 2 more comments
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));}
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 yesterday
answered 2 days ago
nwellnhofnwellnhof
6,53511125
6,53511125
What's the extras
argument you're taking for?
– Shaggy
yesterday
1
@Shaggy Thes
is for the output string.
– nwellnhof
yesterday
It looks like you're initiating it outside the function; do we have a meta consensus that allows C to do that?
– Shaggy
yesterday
@Shaggy I'm not sure what "consensus" means exactly but here's the relevant meta post.
– nwellnhof
yesterday
With "32-bit,", whylong long
instead oflong
orint32_t
,int64_t
,time_t
? IAC, all shorter thanlong long
.
– chux
16 hours ago
|
show 2 more comments
What's the extras
argument you're taking for?
– Shaggy
yesterday
1
@Shaggy Thes
is for the output string.
– nwellnhof
yesterday
It looks like you're initiating it outside the function; do we have a meta consensus that allows C to do that?
– Shaggy
yesterday
@Shaggy I'm not sure what "consensus" means exactly but here's the relevant meta post.
– nwellnhof
yesterday
With "32-bit,", whylong long
instead oflong
orint32_t
,int64_t
,time_t
? IAC, all shorter thanlong long
.
– chux
16 hours ago
What's the extra
s
argument you're taking for?– Shaggy
yesterday
What's the extra
s
argument you're taking for?– Shaggy
yesterday
1
1
@Shaggy The
s
is for the output string.– nwellnhof
yesterday
@Shaggy The
s
is for the output string.– nwellnhof
yesterday
It looks like you're initiating it outside the function; do we have a meta consensus that allows C to do that?
– Shaggy
yesterday
It looks like you're initiating it outside the function; do we have a meta consensus that allows C to do that?
– Shaggy
yesterday
@Shaggy I'm not sure what "consensus" means exactly but here's the relevant meta post.
– nwellnhof
yesterday
@Shaggy I'm not sure what "consensus" means exactly but here's the relevant meta post.
– nwellnhof
yesterday
With "32-bit,", why
long long
instead of long
or int32_t
, int64_t
, time_t
? IAC, all shorter than long long
.– chux
16 hours ago
With "32-bit,", why
long long
instead of long
or int32_t
, int64_t
, time_t
? IAC, all shorter than long long
.– chux
16 hours ago
|
show 2 more comments
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.
1000
->1e3
– Shaggy
yesterday
@Shaggy Of course, thanks!
– AdmBorkBork
56 mins ago
add a comment |
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.
1000
->1e3
– Shaggy
yesterday
@Shaggy Of course, thanks!
– AdmBorkBork
56 mins ago
add a comment |
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.
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 56 mins ago
answered 2 days ago
AdmBorkBorkAdmBorkBork
26.5k364229
26.5k364229
1000
->1e3
– Shaggy
yesterday
@Shaggy Of course, thanks!
– AdmBorkBork
56 mins ago
add a comment |
1000
->1e3
– Shaggy
yesterday
@Shaggy Of course, thanks!
– AdmBorkBork
56 mins ago
1000
-> 1e3
– Shaggy
yesterday
1000
-> 1e3
– Shaggy
yesterday
@Shaggy Of course, thanks!
– AdmBorkBork
56 mins ago
@Shaggy Of course, thanks!
– AdmBorkBork
56 mins ago
add a comment |
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.
1
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?
– Neil A.
2 days ago
2
@NeilA. Yes. The import can go either before or after, the contents of the lambda aren't checked forNameError
s before it's called.
– Erik the Outgolfer
2 days ago
add a comment |
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.
1
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?
– Neil A.
2 days ago
2
@NeilA. Yes. The import can go either before or after, the contents of the lambda aren't checked forNameError
s before it's called.
– Erik the Outgolfer
2 days ago
add a comment |
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.
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 2 days ago
answered 2 days ago
Erik the OutgolferErik the Outgolfer
31.5k429103
31.5k429103
1
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?
– Neil A.
2 days ago
2
@NeilA. Yes. The import can go either before or after, the contents of the lambda aren't checked forNameError
s before it's called.
– Erik the Outgolfer
2 days ago
add a comment |
1
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?
– Neil A.
2 days ago
2
@NeilA. Yes. The import can go either before or after, the contents of the lambda aren't checked forNameError
s before it's called.
– Erik the Outgolfer
2 days ago
1
1
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?– Neil A.
2 days ago
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?– Neil A.
2 days ago
2
2
@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.– Erik the Outgolfer
2 days ago
@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.– Erik the Outgolfer
2 days ago
add a comment |
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 '-'
add a comment |
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 '-'
add a comment |
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 '-'
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 2 days ago
answered 2 days ago
Jo KingJo King
21.3k248110
21.3k248110
add a comment |
add a comment |
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!
1
It seems UnixEpoch is only present in.Net Core 2.1+
– digEmAll
2 days ago
add a comment |
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!
1
It seems UnixEpoch is only present in.Net Core 2.1+
– digEmAll
2 days ago
add a comment |
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!
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 2 days ago
answered 2 days ago
Embodiment of IgnoranceEmbodiment of Ignorance
621115
621115
1
It seems UnixEpoch is only present in.Net Core 2.1+
– digEmAll
2 days ago
add a comment |
1
It seems UnixEpoch is only present in.Net Core 2.1+
– digEmAll
2 days ago
1
1
It seems UnixEpoch is only present in.Net Core 2.1+
– digEmAll
2 days ago
It seems UnixEpoch is only present in.Net Core 2.1+
– digEmAll
2 days ago
add a comment |
R, 58 56 bytes
format(as.POSIXct(scan()/1e3,,'1970-1-1'),'%y%m%d.%H%M')
Try it online!
add a comment |
R, 58 56 bytes
format(as.POSIXct(scan()/1e3,,'1970-1-1'),'%y%m%d.%H%M')
Try it online!
add a comment |
R, 58 56 bytes
format(as.POSIXct(scan()/1e3,,'1970-1-1'),'%y%m%d.%H%M')
Try it online!
R, 58 56 bytes
format(as.POSIXct(scan()/1e3,,'1970-1-1'),'%y%m%d.%H%M')
Try it online!
edited 2 days ago
answered 2 days ago
digEmAlldigEmAll
2,779413
2,779413
add a comment |
add a comment |
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
New contributor
3
You may want to wait a day or so before answering your own questions next time.
– fəˈnɛtɪk
2 days ago
71 bytes
– Luis felipe De jesus Munoz
2 days ago
Alternative 71 bytes
– Shaggy
2 days ago
1
@LuisfelipeDejesusMunoz, that's different enough for you to post yourself.
– Shaggy
2 days ago
@LuisfelipeDejesusMunoz 66 bytes to tie you with Arnauld.
– Shaggy
2 days ago
add a comment |
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
New contributor
3
You may want to wait a day or so before answering your own questions next time.
– fəˈnɛtɪk
2 days ago
71 bytes
– Luis felipe De jesus Munoz
2 days ago
Alternative 71 bytes
– Shaggy
2 days ago
1
@LuisfelipeDejesusMunoz, that's different enough for you to post yourself.
– Shaggy
2 days ago
@LuisfelipeDejesusMunoz 66 bytes to tie you with Arnauld.
– Shaggy
2 days ago
add a comment |
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
New contributor
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
New contributor
edited yesterday
New contributor
answered 2 days ago
skiilaaskiilaa
1637
1637
New contributor
New contributor
3
You may want to wait a day or so before answering your own questions next time.
– fəˈnɛtɪk
2 days ago
71 bytes
– Luis felipe De jesus Munoz
2 days ago
Alternative 71 bytes
– Shaggy
2 days ago
1
@LuisfelipeDejesusMunoz, that's different enough for you to post yourself.
– Shaggy
2 days ago
@LuisfelipeDejesusMunoz 66 bytes to tie you with Arnauld.
– Shaggy
2 days ago
add a comment |
3
You may want to wait a day or so before answering your own questions next time.
– fəˈnɛtɪk
2 days ago
71 bytes
– Luis felipe De jesus Munoz
2 days ago
Alternative 71 bytes
– Shaggy
2 days ago
1
@LuisfelipeDejesusMunoz, that's different enough for you to post yourself.
– Shaggy
2 days ago
@LuisfelipeDejesusMunoz 66 bytes to tie you with Arnauld.
– Shaggy
2 days ago
3
3
You may want to wait a day or so before answering your own questions next time.
– fəˈnɛtɪk
2 days ago
You may want to wait a day or so before answering your own questions next time.
– fəˈnɛtɪk
2 days ago
71 bytes
– Luis felipe De jesus Munoz
2 days ago
71 bytes
– Luis felipe De jesus Munoz
2 days ago
Alternative 71 bytes
– Shaggy
2 days ago
Alternative 71 bytes
– Shaggy
2 days ago
1
1
@LuisfelipeDejesusMunoz, that's different enough for you to post yourself.
– Shaggy
2 days ago
@LuisfelipeDejesusMunoz, that's different enough for you to post yourself.
– Shaggy
2 days ago
@LuisfelipeDejesusMunoz 66 bytes to tie you with Arnauld.
– Shaggy
2 days ago
@LuisfelipeDejesusMunoz 66 bytes to tie you with Arnauld.
– Shaggy
2 days ago
add a comment |
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!
gmtime
is short thanlocaltime
– chux
16 hours ago
Suggestprintf("%02d%02d%02d.%02d%02d",5[l=gmtime(&t)]%100
instead ofl=gmtime(&t);printf("%02d%02d%02d.%02d%02d",l[5]%100
– ceilingcat
4 hours ago
add a comment |
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!
gmtime
is short thanlocaltime
– chux
16 hours ago
Suggestprintf("%02d%02d%02d.%02d%02d",5[l=gmtime(&t)]%100
instead ofl=gmtime(&t);printf("%02d%02d%02d.%02d%02d",l[5]%100
– ceilingcat
4 hours ago
add a comment |
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!
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 2 hours ago
answered 2 days ago
ErikFErikF
1,29917
1,29917
gmtime
is short thanlocaltime
– chux
16 hours ago
Suggestprintf("%02d%02d%02d.%02d%02d",5[l=gmtime(&t)]%100
instead ofl=gmtime(&t);printf("%02d%02d%02d.%02d%02d",l[5]%100
– ceilingcat
4 hours ago
add a comment |
gmtime
is short thanlocaltime
– chux
16 hours ago
Suggestprintf("%02d%02d%02d.%02d%02d",5[l=gmtime(&t)]%100
instead ofl=gmtime(&t);printf("%02d%02d%02d.%02d%02d",l[5]%100
– ceilingcat
4 hours ago
gmtime
is short than localtime
– chux
16 hours ago
gmtime
is short than localtime
– chux
16 hours ago
Suggest
printf("%02d%02d%02d.%02d%02d",5[l=gmtime(&t)]%100
instead of l=gmtime(&t);printf("%02d%02d%02d.%02d%02d",l[5]%100
– ceilingcat
4 hours ago
Suggest
printf("%02d%02d%02d.%02d%02d",5[l=gmtime(&t)]%100
instead of l=gmtime(&t);printf("%02d%02d%02d.%02d%02d",l[5]%100
– ceilingcat
4 hours ago
add a comment |
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!
2
You don't need to count command-line flags anymore.
– AdmBorkBork
2 days ago
Oops. Good to know. Thank you @AdmBorkBork.
– manatwork
2 days ago
add a comment |
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!
2
You don't need to count command-line flags anymore.
– AdmBorkBork
2 days ago
Oops. Good to know. Thank you @AdmBorkBork.
– manatwork
2 days ago
add a comment |
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!
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 2 days ago
manatworkmanatwork
16.3k43572
16.3k43572
2
You don't need to count command-line flags anymore.
– AdmBorkBork
2 days ago
Oops. Good to know. Thank you @AdmBorkBork.
– manatwork
2 days ago
add a comment |
2
You don't need to count command-line flags anymore.
– AdmBorkBork
2 days ago
Oops. Good to know. Thank you @AdmBorkBork.
– manatwork
2 days ago
2
2
You don't need to count command-line flags anymore.
– AdmBorkBork
2 days ago
You don't need to count command-line flags anymore.
– AdmBorkBork
2 days ago
Oops. Good to know. Thank you @AdmBorkBork.
– manatwork
2 days ago
Oops. Good to know. Thank you @AdmBorkBork.
– manatwork
2 days ago
add a comment |
ksh, 36 bytes
printf "%(%y%m%d.%H%M)T" $(($1/1e3))
Try it online!
Thanks to Jo King for 15 bytes saved
The same in Bash would be just 35 characters: Try it online!
– manatwork
23 hours ago
add a comment |
ksh, 36 bytes
printf "%(%y%m%d.%H%M)T" $(($1/1e3))
Try it online!
Thanks to Jo King for 15 bytes saved
The same in Bash would be just 35 characters: Try it online!
– manatwork
23 hours ago
add a comment |
ksh, 36 bytes
printf "%(%y%m%d.%H%M)T" $(($1/1e3))
Try it online!
Thanks to Jo King for 15 bytes saved
ksh, 36 bytes
printf "%(%y%m%d.%H%M)T" $(($1/1e3))
Try it online!
Thanks to Jo King for 15 bytes saved
edited 2 days ago
answered 2 days ago
Sergiy KolodyazhnyySergiy Kolodyazhnyy
331110
331110
The same in Bash would be just 35 characters: Try it online!
– manatwork
23 hours ago
add a comment |
The same in Bash would be just 35 characters: Try it online!
– manatwork
23 hours ago
The same in Bash would be just 35 characters: Try it online!
– manatwork
23 hours ago
The same in Bash would be just 35 characters: Try it online!
– manatwork
23 hours ago
add a comment |
MediaWiki, 46 bytes
{{#time:ymd.Hi|@{{#expr:floor({{{1}}}/1e3)}}}}
add a comment |
MediaWiki, 46 bytes
{{#time:ymd.Hi|@{{#expr:floor({{{1}}}/1e3)}}}}
add a comment |
MediaWiki, 46 bytes
{{#time:ymd.Hi|@{{#expr:floor({{{1}}}/1e3)}}}}
MediaWiki, 46 bytes
{{#time:ymd.Hi|@{{#expr:floor({{{1}}}/1e3)}}}}
answered yesterday
tshtsh
8,50511547
8,50511547
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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 1 hour ago
manatworkmanatwork
16.3k43572
16.3k43572
add a comment |
add a comment |
skiilaa is a new contributor. Be nice, and check out our Code of Conduct.
skiilaa is a new contributor. Be nice, and check out our Code of Conduct.
skiilaa is a new contributor. Be nice, and check out our Code of Conduct.
skiilaa is a new contributor. Be nice, and check out our Code of Conduct.
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');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
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');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
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');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
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');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
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
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?
– AdmBorkBork
2 days ago
1
@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.
– skiilaa
2 days ago
1
Does the timezone matter?
– Erik the Outgolfer
2 days ago
I take it the year is represented by a two digit number?
– Embodiment of Ignorance
2 days ago
1
@FabianRöling timezones don't matter.
– skiilaa
yesterday