C\#현재 총 밀리초 수의 인 스 턴 스 설명 가 져 오기
1970 년 1 월 1 일부 터 현재 시간 까지 의 밀리초 수 를 가 져 오 려 면 코드 는 다음 과 같 습 니 다.
// Ticks
long currentTicks= DateTime .Now.Ticks;
DateTime dtFrom = new DateTime (1970, 1, 1, 0, 0, 0, 0);
long currentMillis = (currentTicks - dtFrom.Ticks) / 10000;
자바환산 단위:
1 초=1000 밀리초
1 밀리초=1000 미묘
1 초
보충:C\#타임 스탬프 byte[]를 datetime 로 바 꾸 는 몇 가지 방법
추천 방법:
DateTime now = DateTime.Now;
byte[] bts = BitConverter.GetBytes(now.ToBinary());
DateTime rt = DateTime.FromBinary(BitConverter.ToInt64(bts, 0));
byte 2 개 를 사 용 했 습 니 다.날짜 범 위 는 2000-01-01~2127-12-31 입 니 다.다음은 전환 방법 입 니 다.
// Date -> byte[2]
public static byte[] DateToByte(DateTime date)
{
int year = date.Year - 2000;
if (year < 0 || year > 127)
return new byte[4];
int month = date.Month;
int day = date.Day;
int date10 = year * 512 + month * 32 + day;
return BitConverter.GetBytes((ushort)date10);
}
// byte[2] -> Date
public static DateTime ByteToDate(byte[] b)
{
int date10 = (int)BitConverter.ToUInt16(b, 0);
int year = date10 / 512 + 2000;
int month = date10 % 512 / 32;
int day = date10 % 512 % 32;
return new DateTime(year, month, day);
}
호출 예:
byte[] write = DateToByte(DateTime.Now.Date);
MessageBox.Show(ByteToDate(write).ToString("yyyy-MM-dd"));
/// <summary> 2. /// BYTE DATETIME 3. /// </summary> 4. /// <param name="bytes"></param> 5. /// <returns></returns> 6. private DateTime BytesToDateTime(byte[] bytes)
{
if (bytes != null && bytes.Length >= 5)
{
int year = 2000 + Convert.ToInt32(BitConverter.ToString(new byte[1] { bytes[0] }, 0));
int month = Convert.ToInt32(BitConverter.ToString(new byte[1] { bytes[1] }, 0));
int date = Convert.ToInt32(BitConverter.ToString(new byte[1] { bytes[2] }, 0));
int hour = Convert.ToInt32(BitConverter.ToString(new byte[1] { bytes[3] }, 0));
int minute = Convert.ToInt32(BitConverter.ToString(new byte[1] { bytes[4] }, 0));
DateTime dt = new DateTime(year, month, date, hour, minute, 0);
return dt;
}
else19. {
return new DateTime();
}
}
이상 은 개인 적 인 경험 이 므 로 여러분 에 게 참고 가 되 기 를 바 랍 니 다.여러분 들 도 저 희 를 많이 응원 해 주시 기 바 랍 니 다.만약 잘못 이 있 거나 완전히 고려 하지 않 은 부분 이 있다 면 아낌없이 가르침 을 주시 기 바 랍 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
WebView2를 Visual Studio 2017 Express에서 사용할 수 있을 때까지Evergreen .Net Framework SDK 4.8 VisualStudio2017에서 NuGet을 사용하기 때문에 패키지 관리 방법을 packages.config 대신 PackageReference를 사용해야...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.