[Include] Plugin-free strftime!
#1

Plugin-free strftime

Introduction
Yes, this is the same one I've released almost a year ago, but this version is fixed up.

So there is a plugin released here which allows scripters to use the strftime function in PAWN. However, I wasn't going to use an entire plugin just for one function when I can replicate it in PAWN!

I could of used the HTTP function, but nobody wants to put an extra file on their webhost. And the HTTP function is really slow.

How it works
Let's say it was Saturday, and I wanted to get the day of the week:

pawn Код:
new str[32];
strftime("Today is %A.", str);
print(str);
Код:
[23:23:15] Today is Saturday.
Or if I wanted to get today's date AND time:

pawn Код:
new str[32];
strftime("%x %X", str);
print(str);
Код:
[23:23:29] 11/10/2013 23:23:29
Or perhaps I want to get the PM or AM designation:

pawn Код:
nwe str[32];
strftime("Time: %I:%M %p", str);
print(str);
Код:
[23:23:37] Time: 11:23 PM
The possibilities are endless!

Functions
There are 2 functions:

pawn Код:
strftime(const string[], dest[]);
Formats the time using the specifiers from string[] and stores the value into dest[].

Example:

pawn Код:
new str[24];
strftime("%I:%M %p", str);
print(str);
pawn Код:
format_time(const string[]);
Basically a wrapper for strftime. Returns the result instead of storing it inside a value.

Example:

pawn Код:
print(format_time("%I:%M %p"));
List of specifiers
Код:
%a - Abbreviated weekday name
%A - Full weekday name
%b - Abbreviated month name
%B - Full month name
%c - Date and time representation
%d - Day of the month (01-31)
%H - Hour in 24h format (00-23)
%I - Hour in 12h format (01-12)
%j - Day of the year (001-366)
%m - Month as a decimal number (01-12)
%M - Minute (00-59)
%p - AM or PM designation
%S - Second (00-61)
%U - Week number with the first Sunday as the first day of week one (00-53)
%w - Weekday as a decimal number with Sunday as 0 (0-6)
%W - Week number with the first Monday as the first day of week one (00-53)
%x - Date representation
%X - Time representation
%y - Year, last two digits (00-99)
%Y - Year
%% - A % sign
Download
Solidfiles
Reply
#2

How and where does it fetch the time from?
Reply
#3

Quote:
Originally Posted by Sublime
Посмотреть сообщение
How and where does it fetch the time from?
This include only uses getdate & gettime and some code that checks for specifiers and adjusts them accordingly.

No external functions are required.
Reply
#4

Good boi, you get a cookie.
Reply
#5

This is cool ;o!
Reply
#6

Looks promising, I'll try it later.
Reply
#7

Good one. Useful One!
Reply
#8

done in a nice way , good job!
Reply
#9

Nice work their Emmet_, I was using CTime plugin, this one will get handy. Thanks.
Reply
#10

Hmm, that doesn't sound too hard to make. Would it be like an extra parameter for "strftime", which uses the specified timestamp instead of the current one?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)