SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 13/11/2013, 08:33 AM   #1
Emmet_
Guest
 
Posts: n/a
Default Plugin-free strftime!

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:

Code:
new str[32];
strftime("Today is %A.", str);
print(str);

Code:
[23:23:15] Today is Saturday.
Or if I wanted to get today's date AND time:

Code:
new str[32];
strftime("%x %X", str);
print(str);

Code:
[23:23:29] 11/10/2013 23:23:29
Or perhaps I want to get the PM or AM designation:

Code:
nwe str[32];
strftime("Time: %I:%M %p", str);
print(str);

Code:
[23:23:37] Time: 11:23 PM
The possibilities are endless!

Functions
There are 2 functions:

Code:
strftime(const string[], dest[]);

Formats the time using the specifiers from string[] and stores the value into dest[].

Example:

Code:
new str[24];
strftime("%I:%M %p", str);
print(str);

Code:
format_time(const string[]);

Basically a wrapper for strftime. Returns the result instead of storing it inside a value.

Example:

Code:
print(format_time("%I:%M %p"));

List of specifiers
Code:
%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 With Quote
Old 13/11/2013, 08:41 AM   #2
Sublime
High-roller
 
Sublime's Avatar
 
Join Date: Jul 2013
Location: 6ix god
Posts: 1,041
Reputation: 223
Default Re: Plugin-free strftime!

How and where does it fetch the time from?
__________________
Quote:
Originally Posted by Zorono View Post
Becuase its the best mod of GTA SA
and itsn't dead, Kalcor is having some proplems on his real life so he is busy now and release the new version now so shut your fucking mouse !!!!!!!!
Sublime is offline   Reply With Quote
Old 13/11/2013, 08:44 AM   #3
Emmet_
Guest
 
Posts: n/a
Default Re: Plugin-free strftime!

Quote:
Originally Posted by Sublime View Post
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 With Quote
Old 13/11/2013, 08:53 AM   #4
Sublime
High-roller
 
Sublime's Avatar
 
Join Date: Jul 2013
Location: 6ix god
Posts: 1,041
Reputation: 223
Default Re: Plugin-free strftime!

Good boi, you get a cookie.
__________________
Quote:
Originally Posted by Zorono View Post
Becuase its the best mod of GTA SA
and itsn't dead, Kalcor is having some proplems on his real life so he is busy now and release the new version now so shut your fucking mouse !!!!!!!!
Sublime is offline   Reply With Quote
Old 13/11/2013, 09:36 AM   #5
Voxel
Gangsta
 
Voxel's Avatar
 
Join Date: Sep 2013
Location: The Netherlands
Posts: 589
Reputation: 68
Default Re: Plugin-free strftime!

This is cool ;o!
__________________
My Work:
[GameMode]The Nether Survival
[Filterscript]SQLite Database Start
[Tutorial]SQLite Commands
[Tutorial]Loot/ Inventory System
[Tutorial]Simple Hunger/Thirst System
[Tutorial]Converting Binary
[Map]Tropical Island + Pier
[Map]San Fierro Apocalypse
Voxel is offline   Reply With Quote
Old 13/11/2013, 01:20 PM   #6
Patrick
Guest
 
Posts: n/a
Default Re: Plugin-free strftime!

Looks promising, I'll try it later.
  Reply With Quote
Old 13/11/2013, 04:54 PM   #7
RedCrossER
Huge Clucker
 
Join Date: Nov 2012
Posts: 277
Reputation: 8
Default Re: Plugin-free strftime!

Good one. Useful One!
RedCrossER is offline   Reply With Quote
Old 13/11/2013, 06:58 PM   #8
Niko_boy
High-roller
 
Niko_boy's Avatar
 
Join Date: Aug 2010
Location: Somewhere i belong
Posts: 1,424
Reputation: 138
Default Re: Plugin-free strftime!

done in a nice way , good job!
__________________
nope
•••[CLOSED]LCS•Freeroam•DM•Stunts•••AutoArena [0.3z][No SkinShot][sixtytiger.com]Want a decent Attack Defend Gamemode?
N/A176.31.229.148:7830Get This! Attack-Defend(v2.3.1)
Niko_boy is offline   Reply With Quote
Old 13/11/2013, 09:43 PM   #9
iZN
High-roller
 
Join Date: Jun 2010
Posts: 2,451
Reputation: 569
Default Re: Plugin-free strftime!

Nice work their Emmet_, I was using CTime plugin, this one will get handy. Thanks.
__________________
iZN is offline   Reply With Quote
Old 28/03/2014, 10:31 PM   #10
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,883
Reputation: 1443
Default Re: Plugin-free strftime!

Very nice, I was going to write one of these but you saved me the time!

Time to see if the server thread freezes disappear now that CTime is removed (someone theorised that CTime caused it)

Edit: Damn it doesn't do what I had hoped (would require a LOT more coding!) I need a library that can take any timestamp as input. I'll go back go writing mine and probably kill myself.
__________________
Tools:

Plugins:

Links:

[HLF]Southclaw is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[FilterScript] Plugin-free GeoIP Slice Filterscripts 132 20/07/2017 12:15 PM
[Include] GVar (Plugin-Free!) Maxips2 Includes 19 29/11/2014 10:40 AM
[Plugin] strftime Jovanny Plugin Development 22 27/09/2012 08:35 PM


All times are GMT. The time now is 01:04 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.