1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | using System; using System.Globalization; using System.Net; using System.Runtime.InteropServices; namespace timechange { internal class Program { [StructLayout(LayoutKind.Sequential)] public struct SYSTEMTIME { public short wYear; public short wMonth; public short wDayOfWeek; public short wDay; public short wHour; public short wMinute; public short wSecond; public short wMilliseconds; } [DllImport( "kernel32.dll" , SetLastError = true )] public static extern bool SetSystemTime( ref SYSTEMTIME st); [DllImport( "kernel32.dll" , SetLastError = true )] public static extern bool SetLocalTime( ref SYSTEMTIME st); static void Main( string [] args) { DateTime dateTime = DateTime.MinValue; try { // 네이버 사이트 시간하고 맞춰서 시간 설정 dateTime = DateTime.ParseExact(response.Headers[ "date" ], "ddd, dd MMM yyyy HH:mm:ss 'GMT'" , CultureInfo.InvariantCulture.DateTimeFormat, DateTimeStyles.AssumeUniversal); } catch (Exception) { dateTime = DateTime.Now; } Console.WriteLine(dateTime); SYSTEMTIME st = new SYSTEMTIME(); st.wYear = ( short )dateTime.Year; st.wMonth = ( short )dateTime.Month; st.wDay = ( short )dateTime.Day; st.wHour = ( short )dateTime.Hour; st.wMinute = ( short )dateTime.Minute; st.wSecond = ( short )dateTime.Second; st.wMilliseconds = ( short )dateTime.Millisecond; SetSystemTime( ref st); SetLocalTime( ref st); Console.ReadKey(); } } } |
22. 7. 7.
C# 내 로컬 PC시간 NAVER 서버 시간으로 변경
피드 구독하기:
글 (Atom)