현재 시간을 어떻게 알 수 있습니까?
현재 시간 (날짜와 시간이 아님)은 어떻게 알 수 있습니까?
예 : 5:42:12 오후
DateTime.Now.TimeOfDay
TimeSpan
(자정부터) 당신에게 그것을 제공합니다 .
DateTime.Now.ToString("h:mm:ss tt")
문자열 로 제공 합니다 .
DateTime 참조 : https://msdn.microsoft.com/en-us/library/system.datetime
String.Format ()을 사용하는 다른 옵션
string.Format("{0:HH:mm:ss tt}", DateTime.Now)
이 시도:
DateTime.Now.ToString("HH:mm:ss tt")
다른 형식의 경우이 사이트를 확인할 수 있습니다. C # DateTime 형식
AM / PM 지정자의 현재 시간 :
DateTime.Now.ToString("hh:mm:ss tt", System.Globalization.DateTimeFormatInfo.InvariantInfo)
DateTime.Now.ToString("hh:mm:ss.fff tt", System.Globalization.DateTimeFormatInfo.InvariantInfo)
0-23 시간 표기법을 사용하는 현재 시간 :
DateTime.Now.ToString("HH:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo)
DateTime.Now.ToString("HH:mm:ss.fff", System.Globalization.DateTimeFormatInfo.InvariantInfo)
DateTime.Now.TimeOfDay
또는
DateTime.Now.ToShortTimeString()
여기 우리는 간다 :
DateTime time = DateTime.Now;
Console.WriteLine(time.ToString("h:mm:ss tt"));
이게 더 나을거야, 이것을 시도 해봐
DateTime.Now.ToShortTimeString();
이를 위해 시간 형식을 지정할 필요가 없습니다.
DateTime.Now.ToString("yyyy-MM-dd h:mm:ss tt");
당신의 필요에 가득 찬 사용을 시도하십시오
현재 날짜와 시간을 얻은 다음 시간 부분 만 사용하십시오. MSDN 문서 에서 날짜 시간 문자열을 형식화 할 수있는 가능성을 살펴보십시오 .
가능한 해결책이 될 수 있습니다.
DateTime now = DateTime.Now;
string time = now.ToString("T");
Datetime.TimeOfDay
를 반환하고 TimeSpan
찾고있는 것일 수 있습니다.
현재 날짜 시간을 계산하려면
DateTime theDate = DateTime.UtcNow;
string custom = theDate.ToString("d");
MessageBox.Show(custom);
24 시간 형식으로 현재 시간 만 표시됩니다.
class Program
{
static void Main(string[] args)
{
Console.WriteLine(DateTime.Now.ToLongTimeString().ToString());
Console.WriteLine(DateTime.Now.ToShortTimeString().ToString());
Console.ReadLine();
}
}
안부
K
매우 간단 DateTime.Now.ToString("hh:mm:ss tt")
var CurDate= DateTime.Now;
CurDate.Hour;
CurDate.Minute;
CurDate.Millisecond
나는 이것도 실험하고 있으며이 페이지들도 도움이된다. 먼저 메인 클래스 ... https://msdn.microsoft.com/en-us/library/system.datetime(v=vs.110).aspx
이제 ToString 메서드의 일부 지정자 형식 ... https://msdn.microsoft.com/en-us/library/system.globalization.datetimeformatinfo(v=vs.110).aspx
예:
using System;
namespace JD
{
class Program
{
public static DateTime get_UTCNow()
{
DateTime UTCNow = DateTime.UtcNow;
int year = UTCNow.Year;
int month = UTCNow.Month;
int day = UTCNow.Day;
int hour = UTCNow.Hour;
int min = UTCNow.Minute;
int sec = UTCNow.Second;
DateTime datetime = new DateTime(year, month, day, hour, min, sec);
return datetime;
}
static void Main(string[] args)
{
DateTime datetime = get_UTCNow();
string time_UTC = datetime.TimeOfDay.ToString();
Console.WriteLine(time_UTC);
Console.ReadLine();
}
}
}
"자정부터의 시간"에 명시된대로 24 시간의 기본값을 얻는다는 것을 보여주기 위해 TimeOfDay 메소드를 던졌습니다.
내 geter method ()를 사용할 수 있습니다. :-디
MyEmail.Body = string.Format("The validation is done at {0:HH:mm:ss} Hrs.",DateTime.Now);
캔을 사용하여 {0:HH:mm:ss}
, {0:HH:mm:ss.fff}
, {0:DD/mm/yyy HH:mm:ss}
, 등 ...
이거 한번 해봐. 3tier Architecture Web Application에서 나를 위해 일하고 있습니다.
"'" + DateTime.Now.ToString() + "'"
삽입 쿼리에서 작은 따옴표를 기억하십시오.
예를 들면 다음과 같습니다.
string Command = @"Insert Into CONFIG_USERS(smallint_empID,smallint_userID,str_username,str_pwd,str_secquestion,str_secanswer,tinyint_roleID,str_phone,str_email,Dt_createdOn,Dt_modifiedOn) values ("
+ u.Employees + ","
+ u.UserID + ",'"
+ u.Username + "','"
+ u.GetPassword() + "','"
+ u.SecQ + "','"
+ u.SecA + "',"
+ u.RoleID + ",'"
+ u.Phone + "','"
+ u.Email + "','"
+ DateTime.Now.ToString() + "','"
+ DateTime.Now.ToString() + "')";
DateTime
라인의 끝에 삽입.
참고 URL : https://stackoverflow.com/questions/296920/how-do-you-get-the-current-time-of-day
'development' 카테고리의 다른 글
이미지가 주어진 미로를 표현하고 해결하기 (0) | 2020.04.02 |
---|---|
JavaScript에서 "어설 션"이란 무엇입니까? (0) | 2020.04.02 |
String의 내용을 C #의 클립 보드로 어떻게 복사합니까? (0) | 2020.04.02 |
코어가 덤프되었지만 코어 파일이 현재 디렉토리에 없습니까? (0) | 2020.04.02 |
Spring Boot의 application.properties 파일에 정의 된 값에 액세스하는 방법 (0) | 2020.04.02 |