문법적으로 현재 작동 시간을 표시하는 문자열을 반환하고 싶습니다. 예를 들어, 3 년 7 개월 11 일 1 시간 16 초 0 초로, 단수 단위가 복수가 아니어야하며, 0 단위는 복수이어야합니다. 아직 발생하지 않았 으면 0으로 표시해서는 안됩니다. (예 : 아직 발생하지 않은 경우 년, 월 등을 표시하지 않음)C에서 문법적으로 올바른 가동 시간
틱 메서드는 한 달 이상 작동하지 않으므로 ManagementObject를 사용하고 있지만 어떻게해야합니까? datetime 계산을하고 세분화합니다. (저는 C#이 매우 새로워서 다양한 함수를 수행하는 유틸리티를 만들어 다양한 것을 배울 수 있습니다.)
이것은 내가 지금 가지고있는 것이며, 많이 지옥 ...
어떤 도움을 주시면 대단히 감사하겠습니다.
public string getUptime()
{
// this should be grammatically correct, meaning, 0 and greater than 1 should be plural, one should be singular
// if it can count in realtime, all the better
// in rare case, clipping can occur if the uptime is really, really huge
// you need a function that stores the boot time in a global variable so it's executed once so repainting this won't slow things down with quer
SelectQuery query = new SelectQuery("SELECT LastBootUpTime FROM Win32_OperatingSystem WHERE Primary='true'");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
foreach (ManagementObject mo in searcher.Get())
{
// this is the start time, do math to figure it out now, hoss
DateTime boot = ManagementDateTimeConverter.ToDateTime(mo.Properties["LastBootUpTime"].Value.ToString());
// or is it better to break up everything into days/hours/etc, i think its better to do that at the end before it gets returned
}
string now = DateTime.Now.ToShortDateString();
return "3 years, 7 months, 11 days, 1 hour, 16 minutes and zero seconds"; // long string for testing label width
}
다른 언어로도이 작업을 수행 할 계획이 없습니까? –