SA-MP Forums Archive
Formatting time correctly - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Formatting time correctly (/showthread.php?tid=192326)



Formatting time correctly - [L3th4l] - 22.11.2010

Well I'm creating this simple time + date script, it works as it should, BUT, i would like to format the date for example, if the 'Hour' is less than 9 , it will show: 09, then 10... That also goes if the 'Hour' AND 'Minute' AND 'Hour' are less than 9, it will print like this: '02:15:02' < Hour, minute, second
pawn Код:
new Hour, Minute, Sec, Day, Month, Year, String[50];
        gettime(Hour, Minute, Sec); getdate(Year, Month, Day);

        if(Hour <= 9 && Sec <= 9)
        {
            format(String, sizeof(String), "      0%d:%d:0%d~n~%s.%d.%d",  Hour, Minute, Sec, GetMonth(), Day, Year);
        }
        else if(Hour <= 9 && Minute <= 9)
        {
            format(String, sizeof(String), "      0%d:0%d:%d~n~%s.%d.%d", Hour, Minute, Sec, GetMonth(), Day, Year);
        }
        else if(Minute <= 9)
        {
            format(String, sizeof(String), "      %d:0%d:%d~n~%s.%d.%d", Hour, Minute, Sec, GetMonth(), Day, Year);
        }
        else format(String, sizeof(String), "      %d:%d:%d~n~%s.%d.%d", Hour, Minute, Sec, GetMonth(), Day, Year);

        TextDrawSetString(PlayerTime, String);
        printf("%s", String);
That's what i got, i been testing it for a while, can't get the correct calculations :P


Re: Formatting time correctly - Cameltoe - 22.11.2010

pawn Код:
stock Zero(number) // inserts a zero infront of an number if number is less then 10
{
    new string[20];
    if(number < 10) format(string, sizeof(string), "0%d", number);
    else format(string, sizeof(string), "%d", number);
    return string;
}



Re: Formatting time correctly - Cameltoe - 22.11.2010

Quote:
Originally Posted by ******
Посмотреть сообщение
That's just a horribly slow and convoluted way of doing exactly what I said!
I just found it around this forum, Haven't tested any of them.


Re: Formatting time correctly - [L3th4l] - 22.11.2010

Thanks ******! Works perfectly!!