| Bytes | Lang | Time | Link |
|---|---|---|---|
| 078 | AWK | 250326T203951Z | xrs |
| 057 | Perl 5 | 250325T180956Z | Xcali |
| 093 | Tcl | 170131T033136Z | sergiol |
| 134 | Go 1.22+ | 240423T183747Z | bigyihsu |
| 038 | Vyxal 3 RṀj | 240423T135922Z | pacman25 |
| 095 | Kotlin | 160531T191336Z | Rames |
| 365 | LOLCODE | 171107T202625Z | qqq |
| 091 | VBA | 171103T183916Z | Taylor R |
| 9094 | Groovy | 171105T205457Z | Hlaaftan |
| 064 | PHP | 160601T104718Z | aross |
| 042 | 05AB1E | 160602T150116Z | Emigna |
| 073 | SmileBASIC | 170130T171912Z | 12Me21 |
| 167 | Batch | 160531T090306Z | Neil |
| 107 | Javascript using external library Enumerable | 160803T175240Z | applejac |
| 095 | JavaScript | 160602T165643Z | Timwi |
| 834 | MarioLANG | 160531T131810Z | Ether Fr |
| 121 | TSQLSQLServer 2012 | 160531T090359Z | t-clause |
| 073 | C | 160531T170434Z | lynn |
| 076 | Sclipting | 160602T182539Z | Timwi |
| 116 | JavaScript ES6 | 160602T132603Z | ASCII-on |
| 091 | C# | 160531T214853Z | AntonB |
| 163 | Foo | 160601T205127Z | SnoringF |
| 030 | Bash + coreutils | 160531T163332Z | Digital |
| 082 | C Function | 160531T163917Z | Giacomo |
| 062 | Ruby | 160601T095101Z | Gosha U. |
| 085 | Swift | 160601T102347Z | GoatInTh |
| nan | JavaScript ES2015 | 160531T120559Z | Leibrug |
| 079 | C++ | 160531T164003Z | anatolyg |
| 100 | C# function | 160601T013728Z | STLDev |
| 034 | MATL | 160531T071015Z | David |
| 107 | PHP | 160531T221231Z | ricdesi |
| 053 | V | 160531T042801Z | DJMcMayh |
| 064 | Julia | 160531T042856Z | Alex A. |
| 120 | Javascript | 160531T160944Z | starcord |
| 160 | /// | 160531T150115Z | Erik the |
| 076 | PowerShell v2+ | 160531T140435Z | AdmBorkB |
| 058 | Perl 5 | 160531T041720Z | msh210 |
| 066 | Python 2 | 160531T035452Z | kennytm |
AWK, 78 bytes
END{for(i--;i++<23;printf"%02d:00%3d:00%s\n",i,x?x:12,(i>11?"pm":"am"))x=i%12}
Tcl, 93 bytes
set i 0
time {puts [format %02d:00%3d:00[expr $i<12?"a":"p"]m $i [expr $i%-12+12]]
incr i} 24
Go 1.22+, 134 bytes
import(."fmt";."time")
func f(){for i:=range 24{d:=Date(0,1,1,i,0,0,0,UTC)
Printf("%s % 7s\n",d.Format("15:00"),d.Format("3:00pm"))
}}
Uses fmt.Printf and time.Time.Format in a pretty straightforward manner.
Prints with trailing newline.
Go, 136 bytes
import(."fmt";."time")
func f(){for i:=0;i<24;i++{d:=Date(0,1,1,i,0,0,0,UTC)
Printf("%s % 7s\n",d.Format("15:00"),d.Format("3:00pm"))
}}
Kotlin, 95 bytes
It can be improved for sure.
fun p(){for(i in 0..23)println("%02d:00 ${(i+11)%12+1}:00${if(i>12)"p" else "a"}m".format(i))}
LOLCODE, 365 bytes
I'll golf down...
HAI 1.3
VISIBLE "00:00 12:00am:)01:00 1:00am:)02:00 2:00am:)03:00 3:00am:)04:00 4:00am:)05:00 5:00am:)06:00 6:00am:)07:00 7:00am:)08:00 8:00am:)09:00 9:00am:)10:00 10:00am:)11:00 11:00am:)12:00 12:00pm:)13:00 1:00pm:)14:00 2:00pm:)15:00 3:00pm:)16:00 4:00pm:)17:00 5:00pm:)18:00 6:00pm:)19:00 7:00pm:)20:00 8:00pm:)21:00 9:00pm:)22:00 10:00pm:)23:00 1:00pm"
KTHXBYE
VBA, 91 Bytes
Anonymous VBE immediate window function that outputs to the VBE immediate window.
For i=0To 23:t=TimeSerial(i,0,0):?Format(t,"hh:mm")Right(" "+Format(t,"h:mmam/pm"),8):Next
Groovy, 90/94 bytes
90 byte version (only works in a script):
24.times{a->s=' ';m=a%12?:12;println"${a<10?0:''}$a:00 ${m<10?s:''}$m:00${a<12?'a':'p'}m"}
94 byte version:
24.times{a->def s=' ',m=a%12?:12;println"${a<10?0:''}$a:00 ${m<10?s:''}$m:00${a<12?'a':'p'}m"}
PHP, 67 65 64 bytes
This uses IBM-850 encoding.
for(;$i<24;)printf(~┌¤═ø┼¤¤┌╠ø┼¤¤┌îÆ§,$i,$i%12?:12,$i++>11?p:a);
With the unencoded string (66 bytes):
for(;$i<24;)printf("%02d:00%3d:00%sm\n",$i,$i%12?:12,$i++>11?p:a);
Run like this:
php -n -r 'for(;$i<24;)printf(~┌¤═ø┼¤¤┌╠ø┼¤¤┌îÆ§,$i,$i%12?:12,$i++>11?p:a);'
Tweaks
- Saved 2 bytes by improving sprintf format
- Saved a byte by getting rid of unnecessary space (thx @Titus)
05AB1E, 51 50 48 44 42 bytes
Saved two bytes thanks to carusocomputing
Code:
24FNgi0}N…:00©ðN12(%12+Dgiðs}®„paN12‹è'mJ,
Explanation
24F # for N in [0...23]
Ngi0} # if len(N)=1, push 0
N # push N
…:00© # push ":00" and store a copy in register
ð # push " "
N12(%12+D # push 2 copies of N%(-12)+12
giðs} # if the length of that number is 1,
# push " " and swap with the number
® # push ":00" again
„pa # push "pa"
N12‹è # index into that with N<12
'm # push "m"
J, # join everything and print with newline
SmileBASIC, 73 bytes
FOR H=0TO 23?FORMAT$(%02D:00 %2D:00%Sm",H,(H+11)MOD 12+1,"ap"[H>11])NEXT
Someone found a better 24->12 hour formula than my old one, which saves 3 bytes, and 5 bytes in another program
Batch, 167 bytes
@echo off
set h=11
set p=a
for /l %%a in (0,1,23)do call:e %%a
exit/b
:e
set a=0%1
set/ah=h%%12+1
set h= %h%
if %1==12 set p=p
echo %a:~-2:00 %h:~-2%:00%p%m
Javascript (using external library - Enumerable) (107 bytes)
_.Range(0,24).WriteLine(x=>((x<10?"0"+x:x)+":00 "+(((h=((x+11)%12)+1))<10?" "+h:h)+":00"+(x<12?"am":"pm")))
Link to library: https://github.com/mvegh1/Enumerable/
Code explanation: Create array of integers from 0 to 23, for each write a line according to the predicate. That predicate checks if current val is less than 10, and pads it with 0, else uses the current val as is. Then adds the minutes string to it. Then basically does a little trickery to convert military to am/pm time, and handles padding for am/pm times less than 10.
JavaScript, 97 95 bytes
This is based off of starcorder’s answer. Thanks to George Reith for a 2 byte improvement.
for(i=0,k=12;i<24;k=i++%12+1)console.log('%s:00 %s:00%sm',i>9?i:'0'+i,k>9?k:' '+k,i>11?'p':'a')
Ungolfed:
for (i=0, k=12; i < 24; k = (i++) % 12 + 1)
console.log('%s:00 %s:00%sm',
i > 9 ? i : '0' + i,
k > 9 ? k : ' ' + k,
i > 11 ? 'p' : 'a')
MarioLANG, 965 834 bytes
well this was ridiculously complicated.
Technically the output is valid but in practice the Tio for MarioLANG output "n " instead of "n" when we print a number with ':'
if I find the time i'll guess i'll try to do a (probably much longer) version of the program that output correctly on Tio
++<>) +++@++++> [!) >)>((((::(.)::((.))+:+:--(.)::)).).).)+++++++++
++""+ +"=====""====#) "+"============================================
+++)+ +>>+++++- <+<)->+++ ![-).).).))(::)).(:(:)))..(((::)).(:+(:((((<
+>+++ ++"====<( ")")-"!+++#=========================================="
+(+++>++!++)<+( ++++-+++++>
-))+)=(#==="+( ++++)+++++"==========================================!
[!!+-[!(+++!!! !+!<+!++!>(((((+:(.))::(((.
==##===#====###=#=#"=##=#"=================<
++++)))+++++++++++++++(((![-).).).)::)).(:)) >
>========================#================== "
+>+ >
+"+ "=======================================[ =====================#===============[
+!> ! -).).).))(::)).)):+(..(((::)).(:+(((((<++!-).).).))(::)).)):+(.(((::)).(:+(((((<
=#==#======================================="==#======================================
Explanation :
our main problem here is the fact that we have 6 NaN char (newLine, Space, :, a, p, m)
in marioLANG, in order to print character, we need their ascii value:
- newLine is 10
- Space is 32
- : is 58
- a is 97
- p is 112
- m is 109
So the first thing to do is to set the memory :
++<>) +++@++++> [!) >)> !
++""+ +"=====""====#) "+"==
+++)+ +>>+++++- <+<)->+++
+>+++ ++"====<( ")")-"!+++
+(+++>++!++)<+( ++++-+++++
-))+)=(#==="+( ++++)+++++
[!!+-[!(+++!!! !+!<+!++!>
==##===#====###=#=#"=##=#"
with this, the memory look like :
v
32 58 0 0 97 109 10 0
_ : a m \n
we will transform a into p during the rest of the program
then we do the actual output :
++<>) +++@++++> [!) >)>((((::(.)::((.))+:+:--(.)::)).).).)+++++++++
++""+ +"=====""====#) "+"============================================
+++)+ +>>+++++- <+<)->+++ ![-).).).))(::)).(:(:)))..(((::)).(:+(:((((<
+>+++ ++"====<( ")")-"!+++#=========================================="
+(+++>++!++)<+( ++++-+++++>
-))+)=(#==="+( ++++)+++++"==========================================!
[!!+-[!(+++!!! !+!<+!++!>(((((+:(.))::(((.
==##===#====###=#=#"=##=#"=================<
++++)))+++++++++++++++(((![-).).).)::)).(:)) >
>========================#================== "
+>+ >
+"+ "=======================================[ =====================#===============[
+!> ! -).).).))(::)).)):+(..(((::)).(:+(((((<++!-).).).))(::)).)):+(.(((::)).(:+(((((<
=#==#======================================="==#======================================
TSQL(SQLServer 2012) 146 124 121
DECLARE @ DATETIME=0WHILE @<1BEGIN PRINT
CONVERT(char(5),@,108)+' '+LOWER(RIGHT(FORMAT(@,'g'),8))SET @=dateadd(hh,1,@)END
First attempt, a bit longer, but a one-liner:
SELECT CONVERT(char(5),n,108)+' '+LOWER(RIGHT(FORMAT(n,'g'),8))FROM(SELECT
top 24 dateadd(hh,Number,0)n FROM master..spt_values WHERE'P'=type)x
C, 73 bytes
m(i){for(i=25;--i;)printf("%02d:00%3d:00%cm\n",24-i,12-i%12,"pa"[i/13]);}
mIllIbyte found a particularly neat way to rewrite this answer. Thanks!
Sclipting, 76 bytes
The program assumes that the input is empty (or '0' or anything that converts to the integer 0).
The byte count assumes UTF-16 encoding.
군上❶겠小꼀虛嗎❷꾣갰글❷결加곀剩增❶겠小글虛嗎댆밁⓷꾣갰⓷⓼곀小掘닐밊終
Ungolfed:
군 // 23
上 // for loop (goes from 0 to 23 if input is 0)
❶겠小꼀虛嗎 // n < 10 ? "0" : ""
❷ // n
꾣갰글 // ":00 "
❷결加곀剩增 // k = (n+11) % 12 + 1
❶겠小글虛嗎 // k < 10 ? " " : ""
댆밁 // "pa"
⓷ // Pull n to top of stack
꾣갰 // ":00"
⓷ // Pull "pa" to top of stack
⓼ // Pull k to top of stack
곀小掘 // "pa"[k < 10 ? 1 : 0]
닐밊 // "m\n"
終 // end of for loop
Each iteration of the loop leaves lots of small strings on the stack; at the end they are all automatically concatenated.
JavaScript (ES6), 119 116 bytes
_=>Array(24).fill().map((_,i)=>`${`0${i}`.slice(-2)}:00 ${` ${(i+11)%12+1}`.slice(-2)}:00${'ap'[+(i>11)]}m`).join`
`
C#, 91 bytes
for(var i=0;i<24;i++){Console.Write($"{i:00}:00 {(i+11)%12+1,2}:00 {(i>11?"p":"a")}m\n");};
Foo, 163 bytes
Pretty brute-force approach; nothing clever here (I tried in a couple spots but it ended up being shorter not to), just wanted to give Foo a shot. Foo automatically prints anything within quotes. $c10 prints a line break. (## ... ) loops until the current cell equals ##.
"00:00 12:00am"$c10+1(10"0"$i":00 "$i":00am"$c10+1)(12$i":00 "$i":00am"$c10+1)"12:00 12:00pm"$c10+1(22$i":00 ">+1$i<":00pm"$c10+1)(24$i":00 ">+1$i<":00pm"$c10+1)
Ungolfed a bit:
"00:00 12:00am"$c10+1
(10"0"$i":00 "$i":00am"$c10+1)
(12$i":00 "$i":00am"$c10+1)
"12:00 12:00pm"$c10+1
(22$i":00 ">+1$i<":00pm"$c10+1)
(24$i":00 ">+1$i<":00pm"$c10+1)
Bash + coreutils, 43 30
- Saved 7 bytes thanks to @Yossarian
- Saved 3 bytes thanks to @AndersKaseorg
seq 0 23|date -f- +%R\ %l:00%P
seqgenerates integers 0-23, one per line.dateinterprets each line as a datetime. Bare integers appear to be sufficient to be recognised as hours of the day bydate.datethen outputs each time with the required formatting using the available time format specifiers.
Assumes LANG=C locale, as per this meta answer.
C Function, 82 bytes
m(i){for(;i<24;printf("%02d:00 %2d:00%cm\n",i,i%12==0?12:i%12,i>11?'p':'a'),i++);}
Usage, 94 Byte
m(i){for(;i<24;printf("%02d:00 %2d:00%cm\n",i,i%12==0?12:i%12,i>11?'p':'a'),i++);}main(){m();}
Ungolfed, 337 Bytes
#include <stdio.h>
void m(){
int i,a;
char c;
for(i=0;i<24;i++){
if (i%12==0){
a = 12;
}
else{
a = i%12;
}
if (i>11){
c = 'p';
} else{
c = 'a';
}
printf("%02d:00 %2d:00%cm\n",i,a,c);
}
}
int main(){
m();
}
it works on Windows:
C Program, 85 bytes
main(i){for(;i<24;printf("%02d:00 %2d:00%cm\n",i,i%12==0?12:i%12,i>11?'p':'a'),i++);}
Ruby, 66 62 bytes
0.upto(23){|i| puts "%02d:00%3d:00#{'ap'[i/12]}m"%[i,(i-1)%12+1]}
New version
24.times{|i|puts"%02d:00%3d:00#{'ap'[i/12]}m"%[i,(i-1)%12+1]}
Swift, 85 bytes
for x in 0...23{print(String(format:"%02d:00 %2d:00\(x<12 ?"a":"p")m",x,12+x % -12))}
JavaScript (ES2015), 147 138 137 134 133 bytes
((o,x,r)=>{for(i=0;i<24;)b=i%12,c=b||12,o+='0'[r](i<10)+i+++x+' '[r]((c<10)+1)+c+x+(i<13?'a':'p')+"m\n";return o})('',':00','repeat')
In this version I took advantage of String.repeat() method to get rid of lengthy .slice() and .join() and moved incrementation inside loop.
Previous version:
((o,x,i)=>{for(;i<24;i++){b=i%12;o+=[`0${i+x}`.slice(-5),(b||12)+x+(i<12?'a':'p')+'m'].join(' '.repeat((b>0&&b<10)+1))+"\n"}return o})('',':00',0)
Gives output with trailing newline. Tested in Firefox Scratchpad. Not sure if passing arguments to IIFE is OK with "no input" rule.
It's my first submission, so hello to everyone! :)
C++, 81 79 bytes
[]{for(time_t t=0,y;t<24;cout<<put_time(gmtime(&y),"%R %l:00%P\n"))y=t++*3600;}
This code requires using namespace std somewhere preceding it.
It does a loop on the values 0...23. It multiplies each value by 3600, converts to a tm struct and prints it. The print format %R outputs the 24-hour and minute; the print formats %l and %P output the proper 12-hour parts; they require GNU.
A working online version is here.
C# function, 100 bytes
void F(){for(int i=0;i<24;i++){Console.Write($"{i:00}:00 {(i+11)%12+1,2}:00 {(i>11?"p":"a")}m\n");}}
Ungolfed version:
void F()
{
for (int i = 0; i < 24; i++)
{
Console.Write($"{i:00}:00 {(i + 11)%12 + 1,2}:00 {(i > 11 ? "p" : "a")}m\n");
}
}
Console.Write() takes too many characters!
MATL, 46 42 34 bytes
12tEt:qy/t15XObZ"!b16XOhhkw14:X~Z)
Previously, 42 bytes, 12tEt:q2M/736330+t15XObZ"!b16XOhhkw14:X~Z), and 46 bytes, 736330 24t:qw/+t15XO' '24TX"b16XOhhk14: 12X~Z). Of course the 736330 wasn't needed, that was crazy!
Note: Doesn't work with TryItOnline, I think there is a compatibility issue between Matlab and Octaves implementation of datestr.
datestr takes the number representation of a date and converts it to the string representation of that date. The time of the day is the fractional part of the number, so 0.0 corrsponds to January 0, 0000, at time 00:00:00, and 1.0 corresponds to January 1, 0000, at 00:00:00. 1/24 is 1am, 2/24 2am etc.
Explanation
12t % push a 12 onto the stack and duplicate
Et % double the 12 and duplicate the 24 (stack now has 12, 24, 24, bottom to top)
:q % make vector 1:24 and decrement by 1, stack has 12, 24, 0:23
y % duplicate second element on stack (24)
/ % divide, for (0:23)/24
t % duplicate elements
15XO % string representation of date, 15 specifies format
b % bubble up element in stack (gets a 24 on top of the stack)
Z"! % makes a column of 24 spaces, to put between columns of times
b % bubble up another (0:23)/24
16XO % string representation of date, 16 for a different format
hh % concatenate two time vectors and the column of spaces
k % convert string to lowercase, because CO gives AM/PM not am/pm
w % swap elements in stack, that first 12 is now on top
14: % vector of equally spaced values 1:14
X~ % set exclusive-or, returns [1 2 3 4 5 6 7 8 9 10 11 13 14]
Z) % get the right columns of the string array to remove extra column of blanks
% implicit display
To show it works in Matlab, here is a screenshot
PHP, 110 107 bytes
for($h=0;$h<24;){$m=($h+11)%12+1;echo($h<10?0:"")."$h:00 ".($m<10?" ":"")."$m:00".($h++<12?"a":"p")."m\n";}
exploded view
for ($h=0; $h<24; ) {
$m = ($h+11) % 12 + 1;
echo ($h < 10 ? 0 : "") . "$h:00 " .
($m < 10 ? " " : "") . "$m:00" . ($h++ < 12 ? "a" : "p") . "m\n";
}
Somewhat surprised, tried to turn the ($i < 10 ? $s : "") . "$i:00" bit into a function, but it wound up adding ~25 characters. No go there.
V, 56 53 bytes
i00:00 23ñYpñH12G$yP13G$pgvó $/am
í/pm
í 0/
í/12
Since this can be hard to enter, here is a reversible hexdump:
00000000: 6930 303a 3030 201b 3233 f159 7001 f148 i00:00 .23.Yp..H
00000010: 1631 3247 2479 5031 3347 2470 6776 f320 .12G$yP13G$pgv.
00000020: 242f 616d 0aed 2f70 6d0a ed20 302f 2020 $/am../pm.. 0/
00000030: 0aed 2f31 320a ../12.
A noncompeting version is trivially 2 bytes shorter if you replace both occurrences of G$ with L, which was supposed to be the same but had a bug.
Explanation:
i00:00<esc> #Enter the starting text.
23ñYp<C-a>ñ #Duplicate and increment 23 times
H #Move back to the beginning
<C-v>12G$y #Select 12 lines horizontally
P #Horizontally paste
13G$p #Move to line 13 and Horizontally paste again
gv #Reselect the top 12 lines
ó $/am #Replace a space at the end of the line with 'am'
í/pm #Replace the previous search with 'pm'
í 0/ #Replace "Space+0" with 2 spaces
í/12 #Replace the previous search with "12"
Julia, 88 71 66 64 bytes
[@printf "%02d:00%3d:00%cm
" i-11 i%12+1 i>22?112:97for i=11:34]
This is a full program that prints the string with a single trailing newline.
Saved 5 bytes thanks to Sp3000 and 2 thanks to Dennis!
Javascript, 122 Bytes, 120 Bytes
f=j=>j>12?j-12:j;for(i=0;i<24;i++)console.log('%s:00 %s:00%s',i<10?'0'+i:i,i==0?12:f(i)<10?' '+f(i):f(i),i>11?'pm':'am')
Edit: Small bug fixed + output:
00:00 12:00am
01:00 1:00am
02:00 2:00am
03:00 3:00am
04:00 4:00am
05:00 5:00am
06:00 6:00am
07:00 7:00am
08:00 8:00am
09:00 9:00am
10:00 10:00am
11:00 11:00am
12:00 12:00pm
13:00 1:00pm
14:00 2:00pm
15:00 3:00pm
16:00 4:00pm
17:00 5:00pm
18:00 6:00pm
19:00 7:00pm
20:00 8:00pm
21:00 9:00pm
22:00 10:00pm
23:00 11:00pm
///, 160 bytes
/Z/:00 //S/Z //A/:00am
//P/:00pm
/00Z12A01S1A02S2A03S3A04S4A05S5A06S6A07S7A08S8A09S9A10Z10A11Z11A12Z12P13S1P14S2P15S3P16S4P17S5P18S6P19S7P20S8P21S9P22Z10P23Z11P
Ungolfed
00:00 12:00am 01:00 1:00am 02:00 2:00am 03:00 3:00am 04:00 4:00am 05:00 5:00am 06:00 6:00am 07:00 7:00am 08:00 8:00am 09:00 9:00am 10:00 10:00am 11:00 11:00am 12:00 12:00pm 13:00 1:00pm 14:00 2:00pm 15:00 3:00pm 16:00 4:00pm 17:00 5:00pm 18:00 6:00pm 19:00 7:00pm 20:00 8:00pm 21:00 9:00pm 22:00 10:00pm 23:00 11:00pm
PowerShell v2+, 76 bytes
0..23|%{"{0:D2}:00{1,3}:00"-f$_,(($_%12),12)[!($_%12)]+('am','pm')[$_-ge12]}
Loops from 0..23 and each loop sets a string with the -f operator. The first {0:D2} ensures we have prepended zeros, the second {1,3} ensures we have padded spaces for the middle column. The {0} one corresponds to the $_ of the -f operator, while the {1} corresponds to the pseudo-ternary that chooses between $_%12 or 12 based on whether $_%12 is non-zero or not (i.e., if we're at $_=13, this will choose 1 for 1:00pm). We then concatenate that with another pseudo-ternary that chooses the appropriate am/pm.
As opposed to my answer on List all times in the day at a half hour rate, it's actually shorter here to brute-force the numbers since we get significantly cheaper padding. Here's the answer using date functions, at 78 bytes
0..23|%{(Date -h $_ -f 'HH:00')+(Date -h $_ -f "h:00tt").ToLower().PadLeft(8)}
Perl 5, 58
map{printf"%02u:00%3u:00%sm
",$_,$_%12||12,$_>11?p:a}0..23
Python 2, 66 bytes
for i in range(24):print'%02d:00%3d:00%sm'%(i,12+i%-12,'ap'[i>11])


