#get time independent of server acrivity

85 messages · Page 1 of 1 (latest)

gleaming bramble
#

Can I get the real lif time without adding 1 to a counter every tick, because I also want it to be accurate when the server is off for a few hours.
I need this because I am making a td game and I want to add daily tasks

fickle violetBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

spice adder
gleaming bramble
#

But that is java....

spice adder
#

ye

gleaming bramble
#

So ill have to make a mod just to get the time?

spice adder
#

no?

#

Java.loadClass()

gleaming bramble
#

Wait what

#

Thats a thing?

spice adder
#

bruh dont tell me you didnt know

gleaming bramble
#

I didn't know

#

How would I have known?

#

So what exactly does this magic do?

spice adder
spice adder
gleaming bramble
#

Can you give me an example to look at?

candid trenchBOT
#

[Quote ➤](#1078321791375781909 message) Doesn't require any addons, place outside of events in startup

const $EventBuses = Java.loadClass('dev.architectury.platform.forge.EventBuses')
const $GasDeferredRegister = Java.loadClass('mekanism.common.registration.impl.GasDeferredRegister')
const $SlurryDeferredRegister = Java.loadClass('mekanism.common.registration.impl.SlurryDeferredRegister')
const $InfuseTypeDeferredRegister = Java.loadClass('mekanism.common.registration.impl.InfuseTypeDeferredRegister')

const GASES = new $GasDeferredRegister('kubejs')
const SLURRY = new $SlurryDeferredRegister('kubejs')
const INFUSETYPE = new $InfuseTypeDeferredRegister('kubejs')

GASES.register('example_gas', 0xA020F0)
SLURRY.register('example_slurry', builder => builder.color(0xA020F0))
INFUSETYPE.register('example_infuse_type', 0xA020F0)

GASES.register($EventBuses.getModEventBus('kubejs').get())
SLURRY['register(net.minecraftforge.eventbus.api.IEventBus)']($EventBuses.getModEventBus('kubejs').get())
INFUSETYPE.register($EventBuses.getModEventBus('kubejs').get())
spice adder
#

#1048591172165189632

lime vigil
#

don't we have Date.now() ? I think Rhino makes this available

spice adder
#

if there is, its unknown to me

lime vigil
#

??tryandsee

#

rip

candid trenchBOT
gleaming bramble
#

Ye thanks a lot

sinful flame
#

??index

candid trenchBOT
# sinful flame ??index

Please close your ticket (with </ticket close:1054771505520717835> or the button atop this thread) once you resolved your issue! This also helps others that would like to help out, as they don't have to look into this thread to check if it has been resolved by now.

Do you have any other questions regarding your issue? Feel free to ask!
Note: You generally should create a new post for unrelated issues.

gleaming bramble
#

don't worry ill close it once I did that

sinful flame
#

??index

candid trenchBOT
# sinful flame ??index

Please post how you solved your issue. Others may find this ticket later, but then have to create another because the actual solution wasn't mentioned. thanks <3

gleaming bramble
sinful flame
#

ok?

gleaming bramble
#

I will do that

#

Anyways, console.logging Date.now() returns this 1.699943804428E12

lime vigil
#

what did you expect?

sinful flame
#

^

gleaming bramble
#

Like 14.11.2023

lime vigil
#

lol

sinful flame
#

did you even read the jsdoc

lime vigil
#

you need to firmat that bri

sinful flame
#

lol

gleaming bramble
#

I know this isn't possible but hoping is allowed right

lime vigil
#

format*

#

if you are going to do math with dates, you need numbers, not 14.11.2023

gleaming bramble
#

Is there like a method .day or so

sinful flame
#

??tryitandsee

candid trenchBOT
sinful flame
#

autocomplete exists

gleaming bramble
#

It suggests NOTHING other than .toFixed .toPrecision

sinful flame
#

what type does it even return

gleaming bramble
#

A number

#

So int I guess

#

How many milliseconds are a second?

lime vigil
#

number

#

you format dates using the result, not after the result

sinful flame
gleaming bramble
#

Nah

lime vigil
#

yes it does

gleaming bramble
#

Oh wait it does

#

Ill just do this /1000/60/60/24

#

And then math.floor it

#

I only need the day

sinful flame
fickle violetBOT
#

Ticket closed!

lime vigil
#

Date(Date.now()).getDay() ?

gleaming bramble
#

Nah

#

[07:54:07] [ERROR] ! tycoon.js#1393: Error occurred while handling event 'ServerEvents.tick': TypeError: Cannot find function getDay in object Tue Nov 14 2023 07:54:07 GMT+0100 (CET).

lime vigil
#

riperino, javadoc says it is deprecated, but wasn't sure about Rhino implementation

what does probejs suggests instead of .getDay() stuff?

gleaming bramble
lime vigil
#

wtf looks like that is already a string not like a Date object/class

#

not useful, Rhino bad

gleaming bramble
#

Bruh

fading glade
#

lul or simlply, use unix time?

gleaming bramble
#

Wdym? How?

fading glade
#

Utils.systemTime

gleaming bramble
#

I mean I already got the time in milliseconds, I would need days

fading glade
#

🤔 milliseconds / 1000 / 60 / 60 / 24

gleaming bramble
#

Yeah but I will have to math.floor this and stuff

#

So if my math understanding is right, the day will be considderd "over" at 12 o'clock

fading glade
#

A3 because js doesn't have a // b, so...```js
const getQuotient = (a, b) => a - a % b

gleaming bramble
#

Yeah thanks