#quick question how I can create an irl time system
1 messages · Page 1 of 1 (latest)
Date.now()
?
quick question do you have a little example?
Date.now() returns the current date in milliseconds
function date(){
const date = Date.now()
world.sendMessage(`${date}`)
}
could this work?
?
can you show me a small example? in scripts
function getDate() {
const date = new Date();
const hours = date.getHours() + 1;
const minutes = date.getMinutes();
const seconds = date.getSeconds();
world.sendMessage(`${hours}:${minutes}:${seconds}`)
}```
@steady elk
i see you speak french so thats your timezone
- 1 is reffering to GMT +1
so whatever GMT + your time zone is, is how many hours to add
ok thank you that's what I'm trying to do thank you
this is not needed, why not use Date.prototype.toString() instead? it'll return all needed information about the time in your timezone
that does not work
what do you mean?
prototype is what will construct methods and properties for instances of an object, Date.prototype.toString() means
const date = new Date();
console.warn(date.toString());
that's probably an issue with the JavaScript environment you're testing your code right now. it should use the system's date to get the local timezone.
Date.prototype.toString() returns a string representation of the Date as interpreted in the local timezone, containing both the date and the time
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toString
this is how it's supposed to work in most JavaScript environments