This is an easy API for parsing times (such as 5m2d) into seconds/minutes/hours etc.
- Tested Minecraft Versions:
- Source Code:
The class is located in sh.okx.timeapi.api.TimeAPI. Remember to import the TimeAPI.jar into your project.
TimeAPI has an accuracy of one second, as such it cannot hold something like 1 millisecond but has getter methods to convert its stored seconds to milliseconds.
First, you'd want to create an instance of TimeAPI:
Then, you can extract information from it (all methods return doubles):Code (Text):TimeAPI api = new TimeAPI("1s 2m 3h"); // Creates a new instance of TimeAPI with 1 second, 2 minutes, and 3 hours.
TimeAPI api = new TimeAPI(seconds);
What can be parsed:Code (Text):
api.getSeconds(); // Would return the amount of total seconds in the TimeAPI instance.
// For example, if you did 'new TimeAPI("5m and 10s");', you'd get 310.
api.getMinutes(); // Same as above, with minutes
api.reparse(String); // Reparses with a new string.
For seconds: s, secs, seconds, sec, second
For minutes: m, mins, minutes, min, minute
For hours: h, hr, hrs, hours, hour
For days: d, dy, dys, day, days
For weeks: w, week, weeks
For months: m, mon, mnth, month, months
For years: y, yr, yrs, year, years
Also, if your string contains 'and', spaces or ',' they will get ignored.
The API will throw an IllegalArgumentException if you use input something like 4asdf.
Examples of Usage:
All the following work with TimeAPI
- 5s, 7d, 9weeks and 22 hours
- 89 secs, 1 hour 17 days
- 7h 2m
- 1 day and 7h
/timeapi <time> Parses a time using the TimeAPI (gives you seconds, minutes, hours, etc);
/timeapi Information about the plugin
description: Parse TimeAPI strings
description: TimeAPI Plugin Info
DO NOT ask for help or request additional things in the reviews. Use the forums.