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"));
}
}
}
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:
// Gets the day of the year represented by this instance.
//
// Returns:
// The day of the year, expressed as a value between 1 and 366.
public int DayOfYear { get; }
//
// Summary:
// Gets the hour component of the date represented by this instance.
//
// Returns:
// The hour component, expressed as a value between 0 and 23.
public int Hour { get; }
//
// Summary:
// Gets a value that indicates whether the time represented by this instance
// is based on local time, Coordinated Universal Time (UTC), or neither.
//
// Returns:
// One of the System.DateTimeKind values. The default is System.DateTimeKind.Unspecified.
public DateTimeKind Kind { get; }
//
// Summary:
// Gets the milliseconds component of the date represented by this instance.
//
// Returns:
// The milliseconds component, expressed as a value between 0 and 999.
public int Millisecond { get; }
//
// Summary:
// Gets the minute component of the date represented by this instance.
//
// Returns:
// The minute component, expressed as a value between 0 and 59.
public int Minute { get; }
//
// Summary:
// Gets the month component of the date represented by this instance.
//
// Returns:
// The month component, expressed as a value between 1 and 12.
public int Month { get; }
//
// Summary:
// Gets a System.DateTime object that is set to the current date and time on
// this computer, expressed as the local time.
//
// Returns:
// A System.DateTime whose value is the current local date and time.
public static DateTime Now { get; }
//
// Summary:
// Gets the seconds component of the date represented by this instance.
//
// Returns:
// The seconds, between 0 and 59.
public int Second { get; }
//
// Summary:
// Gets the number of ticks that represent the date and time of this instance.
//
// Returns:
// The number of ticks that represent the date and time of this instance. The
// value is between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks.
public long Ticks { get; }
//
// Summary:
// Gets the time of day for this instance.
//
// Returns:
// A System.TimeSpan that represents the fraction of the day that has elapsed
// since midnight.
public TimeSpan TimeOfDay { get; }
//
// Summary:
// Gets the current date.
//
// Returns:
// A System.DateTime set to today's date, with the time component set to 00:00:00.
public static DateTime Today { get; }
//
// Summary:
// Gets a System.DateTime object that is set to the current date and time on
// this computer, expressed as the Coordinated Universal Time (UTC).
//
// Returns:
// A System.DateTime whose value is the current UTC date and time.
public static DateTime UtcNow { get; }
//
// Summary:
// Gets the year component of the date represented by this instance.
//
// Returns:
// The year, between 1 and 9999.
public int Year { get; }