O
O
Ovddie2020-09-07 18:12:26
C++ / C#
Ovddie, 2020-09-07 18:12:26

How to create a date in the application?

Good evening! I am a beginner in C#, so I would like to know how to correctly create my date in the application. Code was created to the best of my ability. The question arose - how adequate is this at all and is there an option how to do it more accurately?

public void OnClick() // 
    {
        gameDay++;
        if (gameMonth == 1 && gameDay > 31 || gameMonth == 3 && gameDay > 31 || gameMonth == 4 && gameDay > 30 || gameMonth == 5 && gameDay > 31 || gameMonth == 6 && gameDay > 30 || gameMonth == 7 && gameDay > 31 || gameMonth == 8 && gameDay > 31 || gameMonth == 9 && gameDay > 30 || gameMonth == 10 && gameDay > 31 || gameMonth == 11 && gameDay > 30)
        {
            gameDay = 1;
            gameMonth++;
        }
        if (gameMonth == 2)
        {
            if (gameLeapYear == 0)
            {
                if (gameDay > 29)
                {
                    gameDay = 1;
                    gameMonth++;
                }
            }
            else
            {
                if (gameDay > 28)
                {
                    gameDay = 1;
                    gameMonth++;
                }
            }
        }
        if (gameMonth == 12 && gameDay > 31)
        {
            gameDay = 1;
            gameMonth = 1;
            gameYear++;
            gameLeapYear++;
        }
        if (gameLeapYear > 3)
        {
            gameLeapYear = 0;
        }
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
oleg_ods, 2020-09-07
@Ovddie

https://docs.microsoft.com/en-us/dotnet/api/system...
Maybe you need it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question