30.01.2019, 07:01
Timestamp.inc
A simple time conversion library, wasn't documented but was there in my github for some time. You are able to convert timestamps to date and vise versa.
Supports time zones (GMT) and leap year.
Functions:
https://github.com/Agneese-Saini/SA-.../timestamp.inc
A simple time conversion library, wasn't documented but was there in my github for some time. You are able to convert timestamps to date and vise versa.
Supports time zones (GMT) and leap year.
Functions:
- Timestamp(year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0, hourGMT = 0, minuteGMT = 0);
Returns a timestamp for the given parameters (year, month, etc.).
If year/month/day are left as 0, then the function returns current time timestamp.
Example:
pawn Код:new ts = Timestamp(); // current time - ParseTimestamp(timestamp, &year = 0, &month = 0, &day = 0, &hour = 0, &minute = 0, &second = 0, hourGMT = 0, minuteGMT = 0);
Parses the timestamp into year, month, etc. variables.
Example:
pawn Код:new day, hour; // we just wanna know the day and hour of timestamp
ParseTimestamp(ts, .day = day, .hour = hour);
printf("day = %i, hour = %i", day, hour); 4
// output: "day = 30, hour = 2" - FormatTimestamp(timestamp, const format[], hourGMT = 0, minuteGMT = 0);
Format the timestamp and return as a string.
The length of string returned is defined as "MAX_TIMESTAMP_FORMAT_LENGTH" (value=128).
The available specifiers are:
Код:"%y" - year abbreviated (last 2 chars) "%Y" - full year number "%m" - month number "%b" - month name abbreviated (first 3 chars) "%B" - full month name "%d" - day "%H" - hour (24H clock) "%I" - hour (12H clock) "%p" - AM or PM (12H clock) "%M" - minute "%S" - second
pawn Код:printf(FormatTimestamp(Timestamp(), "%Y-%m-%d %H:%M:%S"));
// output: "2019-30-1 2:54:11"
printf(FormatTimestamp(Timestamp(), "%d %b, %Y"));
// output: "30 January, 2019" - FormatTimeleft(startTimestamp, endTimestamp);
Return the approximate time left between two timestamps.
Example:
pawn Код:new now = Timestamp();
new before = now - ConvertToSeconds(Day, 5); // substract 5 days from current time
printf("%s ago", FormatTimeleft(before, now));
// output: "5 days ago" - ConvertFromSeconds(TimeUnit:type, seconds);
Convert seconds into some other unit.
Available units:
Код:Year, Month, Day, Hour, Minute
- ConvertToSeconds(TimeUnit:type, value);
Convert any given unit value into seconds.
https://github.com/Agneese-Saini/SA-.../timestamp.inc