generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
src/main/java/io/github/blobanium/lt/timestamp/Timestamp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.github.blobanium.lt.timestamp; | ||
|
||
public class Timestamp { | ||
private final long timeInMillis; | ||
private final long timeInNano; | ||
|
||
public Timestamp(){ | ||
timeInNano = System.nanoTime(); | ||
timeInMillis = System.currentTimeMillis(); | ||
} | ||
|
||
public long getTimeInMillis() { | ||
return timeInMillis; | ||
} | ||
|
||
public long getTimeInNano() { | ||
return timeInNano; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/io/github/blobanium/lt/timestamp/TimestampManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.github.blobanium.lt.timestamp; | ||
|
||
public class TimestampManager { | ||
private static final float secondsToMs = 1000.0F; | ||
private static final float secondsToNano = 100000000.0F; | ||
public static float calculateTime(Timestamp stamp, boolean isNano){ | ||
if(isNano){ | ||
return (System.nanoTime() - stamp.getTimeInNano()) / secondsToNano; | ||
}else{ | ||
return (System.currentTimeMillis() - stamp.getTimeInMillis()) / secondsToMs; | ||
} | ||
} | ||
|
||
} |