DateTime.Kind가 get 전용 속성이므로 DateTime.Parse()에서 생성 된 DateTime 객체에 DateTimeKind를 어떻게 할당합니까?C# DateTime 객체에 DateTimeKind 적용
var dte = DateTime.Parse("01/01/2018 10:10:00");
Console.WriteLine("{0} | Kind: {1}", dte, dte.Kind.ToString());
// PRINTS: 1/1/2018 10:10:00 AM | Kind: Unspecified
dte = dte.ToLocalTime();
Console.WriteLine("{0} | Kind: {1}", dte, dte.Kind.ToString());
// PRINTS: 1/1/2018 6:10:00 PM | Kind: Local
// OK, the "Kind" is changed to "Local" which is what I'm trying to achieve
// however it also converted the time!!!
내 질문은 dte.ToUniversal() 또는 dte.ToLocal()를 사용하지 않고 객체 DTE에 UTC 또는 로컬 "종류"를 적용하는 방법 때문에 두 방법의 변환 (또는 변경) 시간
가'DateTimeStyles.AssumeUniversal을 통과 생각해 볼 수 있습니다 : 구문 분석 된 날짜를 사용하여 원하는 DateTimeKind으로 새 날짜 시간을 만들 수, 다음과 같은 DateTimeKind를 사용하는 생성자한다 DateTimeStyles.AdjustToUniversal' (UTC 시간) 또는 현지 시간의 경우 'DateTimeStyles.AssumeLocal' (파싱 후가 아니라 파싱 단계에서이를 수행). –