Skip to content

Archive

Category: C#

1. C#에서 String 형식으로 넘어온 날짜와 시간 데이터를 Datetime 형식으로 형변환 하기
예) string sDate = “20100127″; string sTime = “16:19″;
     -> DateTime _sdt = DateTime.ParseExact(sDate + ” ” + sTime, “yyyyMMdd H:mm”, null);
2. 두 날짜 사이의 시간 간격 구하기
예) TimeSpan tDiff = _edt.Subtract(_sdt);
     if (tDiff.TotalHours > 1)
        Console.Write(”두 날짜 사이의 시간 간격이 1시간을 넘어 갑니다.”);

// 디렉토리 검사 및 생성
string sDirPath;
sDirPath = Application.StartupPath + @”\Log”;
DirectoryInfo di = new DirectoryInfo(sDirPath);
if (di.Exists == false)
{
     di.Create();
}

using System;
using System.Net;
using System.Management;
namespace GetIPCS
{
 /// <summary>
 /// Gets IP addresses of the local machine
 /// </summary>
 class classGetIPCS
 {
  /// <summary>
  /// Gets IP addresses of the local machine
  /// </summary>
  [STAThread]
  static void Main(string[] args)
  {
   ManagementObjectSearcher query = new ManagementObjectSearcher
                (”SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=’TRUE’”);
            ManagementObjectCollection queryCol = query.Get();
            foreach (ManagementObject mo in queryCol)
            {
                string[] address = (string[])mo["IPAddress"];
                string[] subnets = (string[])mo["IPSubnet"];
                [...]