26.10.2015, 19:55
Ftime
Overview:
I was searching through the forum and I didn't see any include or plugin to perform conversions between unix timestamps efficiently, so I was checking the time library made by compuphase and decided to implement their code into a plugin adding the GMT parameter.
This plugin allows you to perform conversions between unix timestamps, it means that if you have a date and time you can convert that to a unix timestamp and vice versa.
Functions:
Code:
native getdayname(year, month, day, string[], len = sizeof(string)); native cvstamp2datetime(timestamp, &year, &month, &day, &hour, &minute, &second, GMT); native cvdatetime2stamp(×tamp, year, month, day, hour, minute, second, GMT);
PHP Code:
new year = 2015, month = 1, day = 5, dName[10];
getdayname(year, month, day, dName);
printf("%d/%d/%d was %s.", day, month, year, dName);
Code:
5/1/2015 was Monday.
PHP Code:
new timestamp = 1445842664, year, month, day, hour, minute, second;
cvstamp2datetime(timestamp, year, month, day, hour, minute, second, -5);
printf("[Time] %d:%d:%d | [Date] %d/%d/%d", hour, minute, second, day, month, year);
Code:
[Time] 1:57:44 | [Date] 26/10/2015
PHP Code:
new timestamp, year = 2015, month = 10, day = 26, hour = 1, minute = 57, second = 44;
cvdatetime2stamp(timestamp, year, month, day, hour, minute, second, -5);
printf("[Time] %d:%d:%d | [Date] %d/%d/%d outputs %d as an unix timestamp.", hour, minute, second, day, month, year, timestamp);
Code:
[Time] 1:57:44 | [Date] 26/10/2015 outputs 1445842664 as an unix timestamp.
Using Slice's benchmark macros I got the following results.
Code:
Bench for cvstamp2datetime: executes, by average, 1516.13 times/ms. Bench for cvdatetime2stamp: executes, by average, 1684.50 times/ms. Bench for getdayname: executes, by average, 1730.83 times/ms.
- ThePhenix
- Crayder
- Compuphase
Release + Source code
Github