ID:2278909
 
(See the best response by Ter13.)
Code:
function displayTime() {
var str = "";

var currentTime = new Date()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()
var seconds = currentTime.getSeconds()

if (minutes < 10) {
minutes = "0" + minutes
}
if (seconds < 10) {
seconds = "0" + seconds
}
str += hours + ":" + minutes + ":" + seconds + " ";
if(hours > 11){
str += "PM"
} else {
str += "AM"
}
return str;
}


Problem description:
I trying to make a working timestamp code for my game. I don't want the year just hours minutes seconds to appear on Worldchat before the usrs tags.
Best response
BYOND has built in 24 hour timestamps via time2text.

time2text(world.timeofday,"hh:mm:ss")


But you want 12 hour timestamps. Lemme just rewrite that javascript you included in your post as DM instead.

proc
displayTime()
var/timestamp = world.timeofday
var/hours = round(timestamp / 36000) //3600 seconds in an hour
var/minutes = round((timestamp % 36000) / 600) //60 seconds in a minute
var/seconds = round((timestamp % 600) / 10) //10 deciseconds in a second
var/period = "AM"

if(hours>=12)
hours -= 12
period = "PM"
if(hours==0)
hours = 12

if(minutes<10)
minutes = "0[minutes]"
if(seconds<10)
seconds = "0[seconds]"

return "[hours]:[minutes]:[seconds] [period]"


world.timeofday holds the time since midnight of the current day in deciseconds. world.realtime holds the time in deciseconds since Jan 1, 2000.
Thank you.