Formatting time correctly
#1

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
Reply
#2

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;
}
Reply
#3

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.
Reply
#4

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


Forum Jump:


Users browsing this thread: 1 Guest(s)