c#输出当前日期和当前时间_如何在C#中的当前日期时间添加分钟?

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

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

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

Syntax:

句法:

    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#代码在当前日期时间添加分钟

using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            //creating an object of DateTime class
            //and, initializing it with the current time 
            //using "Now"           
            DateTime dt1 = DateTime.Now;

            //printing current date time
            Console.WriteLine("Currnt date time is: " + dt1.ToString());
            
            //another DateTime object to store the updated date time
            //adding 15 minutes
            DateTime dt2 = dt1.AddMinutes(15);
            //updated date time is 
            Console.WriteLine("Updated date time is: " + dt2.ToString());

            //adding 2880 minutes (i.e. 2 days) in the time 
            dt2 = dt1.AddMinutes(2880);
            //updated date time is 
            Console.WriteLine("Updated date time is: " + dt2.ToString());

            //just to print a new line
            Console.WriteLine();
        }
    }
}

Output

输出量

RUN 1:
Currnt date time is: 10/17/2019 5:05:43 PM
Updated date time is: 10/17/2019 5:20:43 PM
Updated date time is: 10/19/2019 5:05:43 PM

RUN 2:
Currnt date time is: 10/17/2019 5:06:19 PM
Updated date time is: 10/17/2019 5:21:19 PM
Updated date time is: 10/19/2019 5:06:19 PM


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

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

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值