C# Add 30 Days to a Date: Example & Code
To add 30 days to a given date in C#, you can use the DateTime class and its AddDays method. Here's an example:\n\ncsharp\nDateTime originalDate = new DateTime(2023, 06, 12);\nDateTime newDate = originalDate.AddDays(30);\n\nConsole.WriteLine(newDate.ToString("yyyy-MM-dd")); // Output: 2023-07-12\n\n\nIn this example, we create a DateTime object originalDate representing June 12, 2023. Then, we use the AddDays method to add 30 days to the original date, resulting in the new date stored in the newDate variable. Finally, we print the new date using the desired format.
原文地址: https://www.cveoy.top/t/topic/pHqM 著作权归作者所有。请勿转载和采集!