分享

c#输出当前日期和当前时间...

 此生不想做圣贤 2021-10-06

c#输出当前日期和当前时间

To add minutes in the current date-time, we use AddMinutes() method of DateTime class in C#.

在当前日期时间添加分钟 ,我们在C#中使用DateTime类的AddMinutes()方法。

Syntax:

句法:

  1. DateTime DateTime.AddMinutes(double);

AddMinutes() method accepts the value of the minutes as double and returns the DateTime object that can be parsed and updated date time can be found.

AddMinutes()方法将分钟的值接受为两倍,并返回可以解析的DateTime对象,并可以找到更新的日期时间。

C# code to add minutes in current date time

C#代码在当前日期时间添加分钟

  1. using System;
  2. namespace ConsoleApplication1
  3. {
  4. class Program
  5. {
  6. static void Main(string[] args)
  7. {
  8. //creating an object of DateTime class
  9. //and, initializing it with the current time
  10. //using "Now"
  11. DateTime dt1 = DateTime.Now;
  12. //printing current date time
  13. Console.WriteLine("Currnt date time is: " + dt1.ToString());
  14. //another DateTime object to store the updated date time
  15. //adding 15 minutes
  16. DateTime dt2 = dt1.AddMinutes(15);
  17. //updated date time is
  18. Console.WriteLine("Updated date time is: " + dt2.ToString());
  19. //adding 2880 minutes (i.e. 2 days) in the time
  20. dt2 = dt1.AddMinutes(2880);
  21. //updated date time is
  22. Console.WriteLine("Updated date time is: " + dt2.ToString());
  23. //just to print a new line
  24. Console.WriteLine();
  25. }
  26. }
  27. }

Output

输出量

  1. RUN 1:
  2. Currnt date time is: 10/17/2019 5:05:43 PM
  3. Updated date time is: 10/17/2019 5:20:43 PM
  4. Updated date time is: 10/19/2019 5:05:43 PM
  5. RUN 2:
  6. Currnt date time is: 10/17/2019 5:06:19 PM
  7. Updated date time is: 10/17/2019 5:21:19 PM
  8. Updated date time is: 10/19/2019 5:06:19 PM

翻译自: https://www./dot-net/add-minutes-in-the-current-date-time-in-csharp.aspx

c#输出当前日期和当前时间

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多