logo

English

이곳의 프로그래밍관련 정보와 소스는 마음대로 활용하셔도 좋습니다. 다만 쓰시기 전에 통보 정도는 해주시는 것이 예의 일것 같습니다. 질문이나 오류 수정은 siseong@gmail.com 으로 주세요. 감사합니다.

[C#] 코드 실행 시간 측정 및 DateTime 스트링으로 변환 포맷

by lizard2019 posted Jan 23, 2019
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print

코드 실행 시간 측정 

 

        static string MeasureRunTime(DateTime startDateTime)

        {

            DateTime endDateTime = new DateTime();

            endDateTime = DateTime.Now;

            DateTime lapTIme = new DateTime() + endDateTime.Subtract(startDateTime);

 

            return lapTIme.ToString("mm:ss");

        }

 

...

            DateTime startDateTime = new DateTime();

            startDateTime = DateTime.Now;

 

            수행 코드

 

            label3.Text = MeasureRunTime(startDateTime);

 

...

 

 

DataTime 형식을 스트링으로 표시하는 방법은 표를 참조.

 

Format E.g. Result
DateTime.Now.ToString("MM/dd/yyyy") 05/29/2015
DateTime.Now.ToString("dddd, dd MMMM yyyy") Friday, 29 May 2015
DateTime.Now.ToString("dddd, dd MMMM yyyy") Friday, 29 May 2015 05:50
DateTime.Now.ToString("dddd, dd MMMM yyyy") Friday, 29 May 2015 05:50 AM
DateTime.Now.ToString("dddd, dd MMMM yyyy") Friday, 29 May 2015 5:50
DateTime.Now.ToString("dddd, dd MMMM yyyy") Friday, 29 May 2015 5:50 AM
DateTime.Now.ToString("dddd, dd MMMM yyyy HH:mm:ss") Friday, 29 May 2015 05:50:06
DateTime.Now.ToString("MM/dd/yyyy HH:mm") 05/29/2015 05:50
DateTime.Now.ToString("MM/dd/yyyy hh:mm tt") 05/29/2015 05:50 AM
DateTime.Now.ToString("MM/dd/yyyy H:mm") 05/29/2015 5:50
DateTime.Now.ToString("MM/dd/yyyy h:mm tt") 05/29/2015 5:50 AM
DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss") 05/29/2015 05:50:06
DateTime.Now.ToString("MMMM dd") May 29
DateTime.Now.ToString("yyyy’-‘MM’-‘dd’T’HH’:’mm’:’ss.fffffffK") 2015-05-16T05:50:06.7199222-04:00
DateTime.Now.ToString("ddd, dd MMM yyy HH’:’mm’:’ss ‘GMT’") Fri, 16 May 2015 05:50:06 GMT
DateTime.Now.ToString("yyyy’-‘MM’-‘dd’T’HH’:’mm’:’ss") 2015-05-16T05:50:06
DateTime.Now.ToString("HH:mm") 05:50
DateTime.Now.ToString("hh:mm tt") 05:50 AM
DateTime.Now.ToString("H:mm") 5:50
DateTime.Now.ToString("h:mm tt") 5:50 AM
DateTime.Now.ToString("HH:mm:ss") 05:50:06
DateTime.Now.ToString("yyyy MMMM") 2015 May
  1. d -> Represents the day of the month as a number from 1 through 31. 
     
  2. dd -> Represents the day of the month as a number from 01 through 31. 
     
  3. ddd-> Represents the abbreviated name of the day (Mon, Tues, Wed etc).
     
  4. dddd-> Represents the full name of the day (Monday, Tuesday etc).
     
  5. h 12-hour clock hour (e.g. 4).
     
  6. hh 12-hour clock, with a leading 0 (e.g. 06)
     
  7. H 24-hour clock hour (e.g. 15)
     
  8. HH 24-hour clock hour, with a leading 0 (e.g. 22)
     
  9. m Minutes
     
  10. mm Minutes with a leading zero
     
  11. M Month number(eg.3)
     
  12. MM Month number with leading zero(eg.04)
     
  13. MMM Abbreviated Month Name (e.g. Dec)
     
  14. MMMM Full month name (e.g. December)
     
  15. s Seconds
     
  16. ss Seconds with leading zero
     
  17. t Abbreviated AM / PM (e.g. A or P)
     
  18. tt AM / PM (e.g. AM or PM
     
  19. y Year, no leading zero (e.g. 2015 would be 15)
     
  20. yy Year, leadin zero (e.g. 2015 would be 015)
     
  21. yyy Year, (e.g. 2015)
     
  22. yyyy Year, (e.g. 2015)
     
  23. K Represents the time zone information of a date and time value (e.g. +05:00)
     
  24. z With DateTime values, represents the signed offset of the local operating system's time zone from

    Coordinated Universal Time (UTC), measured in hours. (e.g. +6)
     
  25. zz As z, but with leading zero (e.g. +06)
     
  26. zzz With DateTime values, represents the signed offset of the local operating system's time zone from UTC,measured in hours and minutes. (e.g. +06:00)
     
  27. f Represents the most significant digit of the seconds fraction; that is, it represents the tenths of a second in a date and time value.
     
  28. ff Represents the two most significant digits of the seconds fraction in date and time
     
  29. fff Represents the three most significant digits of the seconds fraction; that is, it represents the milliseconds in a date and time value.
     
  30. ffff Represents the four most significant digits of the seconds fraction; that is, it represents the ten thousandths of a second in a date and time value. While it is possible to display the ten thousandths of a second component of a time value, that value may not be meaningful.
     
  31. fffff Represents the five most significant digits of the seconds fraction; that is, it represents the hundred thousandths of a second in a date and time value. 
     
  32. ffffff Represents the six most significant digits of the seconds fraction; that is, it represents the millionths of a Second in a date and time value.
     
  33. fffffff Represents the seven most significant digits of the seconds fraction; that is, it represents the ten millionths of a second in a date and time value.
TAG •

List of Articles
No. Subject Author Date Views
45 세마포어의 개념과 사용법 digipine 2017.10.29 765
44 [Windows] DOS 명령어 실행하고 결과 스트링 가져오는 샘플 코드 digipine 2017.11.02 2689
43 [WINCE] 키보드 및 마우스 메시지 후킹하기 digipine 2017.10.29 809
42 [WINCE] 메모리카드 상태 감시 digipine 2017.10.29 327
41 [WINCE] Process, Thread API 함수 사용법 digipine 2017.10.29 960
40 [WINCE] MulDiv 함수 구현 digipine 2017.10.29 699
39 [WINCE] IAT Hooking 방법과 소스 코드 digipine 2017.10.29 659
38 [WIN32] 파일 핸들로 파일 명 구하기 digipine 2017.10.29 1066
37 [WIN32] 실행 중인 프로세스를 외부에서 강제로 종료, 안전한 TerminateProcess digipine 2017.10.29 3460
36 [WIN32] Process ID로 HWND 구하기 digipine 2017.10.29 5019
35 [Win32] HBITMAP Contrast 조절하는 코드 - RGB 이미지 보정 엉뚱도마뱀 2018.05.04 737
34 [WIN32] API Hook 정리 문서 digipine 2017.10.29 1970
33 [WIN32, WINCE] 디스크 용량 구하는 방법 API GetDiskFreeSpaceEx digipine 2017.10.29 1569
32 [Win API]프로세스 아이디와 윈도우 핸들을 이용 파일명 구하기 digipine 2017.10.29 1393
31 [VC++, WInAPI] 폴더를 통채로 지우기, 서브 폴더 포함, DeleteAllFiles digipine 2017.10.29 1763
30 [MFC] Dialog에서 부모 윈도우 알아내기 digipine 2017.10.28 923
29 [DirectShow] 화면 원본 비율유지 digipine 2017.10.29 960
28 [C#] 프로그램 종료 방법 lizard2019 2019.01.23 6789
» [C#] 코드 실행 시간 측정 및 DateTime 스트링으로 변환 포맷 lizard2019 2019.01.23 23018
26 [C#] StreamReader 에서의 한글 Encoding 문제 digipine 2017.10.29 1000
Board Pagination Prev 1 2 3 Next
/ 3