SanaTime c # dan soniyani o'chirish

UNIX vaqt tamg'asini qiymatini standart vaqtga aylantirgan kodning bir qismi bor, lekin soat, daqiqa va soniya qaytib keladi. Men faqat soat va daqiqalarni qaytarib olishni xohlayman.

convertSunriseTime = UnixTimeStampToDateTime(currentSunriseTime).ToString();
convertSunsetTime = UnixTimeStampToDateTime(currentSunsetTime).ToString();

private static TimeSpan UnixTimeStampToDateTime(long unixTimeStamp)
{
    DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
    dtDateTime = dtDateTime.AddSeconds(unixTimeStamp);
    return dtDateTime.TimeOfDay;
}

va moment convertSunriseTime va convertSunsetTime daqiqalar bilan qaytib kelishi kerak.

0
Shunday qilib, natijaning aniqligi ni faqat daqiqalar bilan cheklashni xohlaysizmi? Yonaltiruvchi vaqt belgilarini to'liq bo'lmagan daqiqalar bilan qanday qilib ishlatishni istaysiz?
qo'shib qo'ydi muallif driis, manba
Shunday qilib, natijaning aniqligi ni faqat daqiqalar bilan cheklashni xohlaysizmi? Yonaltiruvchi vaqt belgilarini to'liq bo'lmagan daqiqalar bilan qanday qilib ishlatishni istaysiz?
qo'shib qo'ydi muallif driis, manba
Men sizni qiymatni formatlash bilan chalkashtirib yuborgan deb o'ylayman. Qiymati bir necha daqiqaga qanchalik aylantirishi mumkinligini sizga aytishimiz mumkin, ammo TimeSpan hali ham xuddi shunday aniqlikka ega. qiymatini faqat soat va minutlarni ko'rsatish uchun formatlashni xohlaysizmi?
qo'shib qo'ydi muallif driis, manba
Men sizni qiymatni formatlash bilan chalkashtirib yuborgan deb o'ylayman. Qiymati bir necha daqiqaga qanchalik aylantirishi mumkinligini sizga aytishimiz mumkin, ammo TimeSpan hali ham xuddi shunday aniqlikka ega. qiymatini faqat soat va minutlarni ko'rsatish uchun formatlashni xohlaysizmi?
qo'shib qo'ydi muallif driis, manba
Shuningdek, soatlab ham. HH formatida: mm. Men buni bir daqiqada yoki ikkitadan ajratib qo'yganim yo'q.
qo'shib qo'ydi muallif Ross, manba
Shuningdek, soatlab ham. HH formatida: mm. Men buni bir daqiqada yoki ikkitadan ajratib qo'yganim yo'q.
qo'shib qo'ydi muallif Ross, manba
Ha, men shuni xohlayman.
qo'shib qo'ydi muallif Ross, manba
Ha, men shuni xohlayman.
qo'shib qo'ydi muallif Ross, manba

6 javoblar

Shunday qilib, soat va daqiqalarni ko'rsatish uchun qiymatingizni formatlashni xohlaysiz. Buni qilishingiz mumkin:

convertSunriseTime = UnixTimeStampToDateTime(currentSunriseTime).ToString("hh\\:mm");

Here, the parameter to the ToString() method specifies that you are only interested in getting the hours and minutes parts into the resulting string. This is called a custom TimeSpan format string. There is also a set of standard ones: Standard TimeSpan format strings

1
qo'shib qo'ydi

Shunday qilib, soat va daqiqalarni ko'rsatish uchun qiymatingizni formatlashni xohlaysiz. Buni qilishingiz mumkin:

convertSunriseTime = UnixTimeStampToDateTime(currentSunriseTime).ToString("hh\\:mm");

Here, the parameter to the ToString() method specifies that you are only interested in getting the hours and minutes parts into the resulting string. This is called a custom TimeSpan format string. There is also a set of standard ones: Standard TimeSpan format strings

1
qo'shib qo'ydi

bu ishni bajarishi mumkin:

private static TimeSpan UnixTimeStampToDateTime(long unixTimeStamp)
{
    DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
    dtDateTime = dtDateTime.AddSeconds(unixTimeStamp);
    dtDateTime = DateTime.FromMinutes((int)dtdateTime.TotalMinutes);
    return dtDateTime.TimeOfDay;
}
0
qo'shib qo'ydi

bu ishni bajarishi mumkin:

private static TimeSpan UnixTimeStampToDateTime(long unixTimeStamp)
{
    DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
    dtDateTime = dtDateTime.AddSeconds(unixTimeStamp);
    dtDateTime = DateTime.FromMinutes((int)dtdateTime.TotalMinutes);
    return dtDateTime.TimeOfDay;
}
0
qo'shib qo'ydi
Can you try this way 
convertSunriseTime = UnixTimeStampToDateTime(currentSunriseTime).ToString();
convertSunsetTime = UnixTimeStampToDateTime(currentSunsetTime).ToString();
private static TimeSpan UnixTimeStampToDateTime(long unixTimeStamp) 

{
        
DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
    
dtDateTime = dtDateTime.AddSeconds(unixTimeStamp);
        
return dtDateTime.TimeOfDay;

}


0
qo'shib qo'ydi
Can you try this way 
convertSunriseTime = UnixTimeStampToDateTime(currentSunriseTime).ToString();
convertSunsetTime = UnixTimeStampToDateTime(currentSunsetTime).ToString();
private static TimeSpan UnixTimeStampToDateTime(long unixTimeStamp) 

{
        
DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
    
dtDateTime = dtDateTime.AddSeconds(unixTimeStamp);
        
return dtDateTime.TimeOfDay;

}


0
qo'shib qo'ydi