本篇內(nèi)容介紹了“C#怎么獲取某個(gè)時(shí)間點(diǎn)”的有關(guān)知識(shí),在實(shí)際案例的操作過(guò)程中,不少人都會(huì)遇到這樣的困境,接下來(lái)就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
創(chuàng)新互聯(lián)主營(yíng)鹽亭網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,app軟件開發(fā)公司,鹽亭h5小程序開發(fā)搭建,鹽亭網(wǎng)站營(yíng)銷推廣歡迎鹽亭等地區(qū)企業(yè)咨詢C# 獲取某個(gè)時(shí)間的0點(diǎn)0分和23點(diǎn)59分59秒,具體代碼如下所示:
C#獲取當(dāng)月第一天和最后一天當(dāng)月第一天0時(shí)0分0秒:
DateTime.Now.AddDays(1 - DateTime.Now.Day).Date當(dāng)月最后一天23時(shí)59分59秒:DateTime.Now.AddDays(1 - DateTime.Now.Day).Date.AddMonths(1).AddSeconds(-1)C#獲取上個(gè)月第一天和最后一天上個(gè)月第一天0時(shí)0分0秒:DateTime.Now.AddMonths(-1).Date.AddDays(1 - DateTime.Now.Day);上個(gè)月最后一天23時(shí)59分59秒:DateTime.Parse(DateTime.Now.AddDays(1 - DateTime.Now.Day).ToShortDateString()).AddSeconds(-1).ToString();當(dāng)天0時(shí)0分0秒:DateTime start = Convert.ToDateTime(DateTime.Now.ToString("D").ToString());當(dāng)天23時(shí)59分59秒:DateTime end = Convert.ToDateTime(DateTime.Now.AddDays(1).ToString("D").ToString()).AddSeconds(-1);
知識(shí)點(diǎn)擴(kuò)展:java 獲取某一日期的0點(diǎn)0分0秒和23點(diǎn)59分59秒
public String DateToStringBeginOrEnd(Date date,Boolean flag) { String time = null; SimpleDateFormat dateformat1 = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); Calendar calendar1 = Calendar.getInstance(); //獲取某一天的0點(diǎn)0分0秒 或者 23點(diǎn)59分59秒 if (flag == true) { calendar1.setTime(date); calendar1.set(calendar1.get(Calendar.YEAR), calendar1.get(Calendar.MONTH), calendar1.get(Calendar.DAY_OF_MONTH), 0, 0, 0); Date beginOfDate = calendar1.getTime(); time = dateformat1.format(beginOfDate); System.out.println(time); }else{ Calendar calendar2 = Calendar.getInstance(); calendar2.setTime(date); calendar1.set(calendar2.get(Calendar.YEAR), calendar2.get(Calendar.MONTH), calendar2.get(Calendar.DAY_OF_MONTH), 23, 59, 59); Date endOfDate = calendar1.getTime(); time = dateformat1.format(endOfDate); System.out.println(time); } return time;}
“C#怎么獲取某個(gè)時(shí)間點(diǎn)”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!