日期:2014-05-17  浏览次数:21082 次

c# datetime数据修改
如何修改datetime数据里面的数据,比如将毫秒改为1,月改为2,其余不变

------解决方案--------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime dt = DateTime.Now;
            dt = new DateTime(dt.Year, 2, dt.Day, dt.Hour, dt.Minute, dt.Second, 1);
            Console.WriteLine(dt.ToString("yyyy-MM-dd hh:mm:ss.fff"));
        }
    }
}


2013-02-08 11:13:36.001
Press any key to continue . . .
------解决方案--------------------
DateTime dt = DateTime.Now;
DateTime d = new DateTime(dt.Year, dt.Month, 2);
这样月就变成2月了
------解决方案--------------------
引用:
不是增加,也不是创建,是修改啊


楼主是程序员么?怀疑中
你看看DataTime定义

public DateTime Date { get; }
        //
        // Summary:
        //     Gets the day of the month represented by this instance.
        //
        // Returns:
        //     The day component, expressed as a value between 1 and 31.
        public int Day { get; }
        //
        // Summary:
        //     Gets the day of the week represented by this instance.
        //
        // Returns:
        //     A System.DayOfWeek enumerated constant that indicates the day of the week
        //     of this System.DateTime value.
        public DayOfWeek DayOfWeek { get; }
        //
        // Summary:
        //