Java 各種時間上的操作範例
分享一些在專案中用到JAVA與日期相關的操作,包括:
- 取得目前的年、月、日
- 判斷兩個日期的大小
- 計算兩個日期的差距
- 取得昨天的日期
- 取得上個月的開始與結束日
package CDIT.stanley; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.util.Calendar; public class dateOperation { public static int differentDays(Date date1,Date date2){ Calendar cal1 = Calendar.getInstance(); cal1.setTime(date1); Calendar cal2 = Calendar.getInstance(); cal2.setTime(date2); int day1= cal1.get(Calendar.DAY_OF_YEAR); int day2 = cal2.get(Calendar.DAY_OF_YEAR); int year1 = cal1.get(Calendar.YEAR); int year2 = cal2.get(Calendar.YEAR); if(year1 != year2){ int timeDistance = 0 ; for(int i = year1 ; i < year2 ; i ++){ if(i%4==0 && i%100!=0 || i%400==0){ timeDistance += 366; } else{ timeDistance += 365; } } return timeDistance + (day2-day1) ; } else{ return day2-day1; } } public static Date getFirstMonthDay(Calendar calendar) { calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DATE)); return calendar.getTime(); } public static Date getLastMonthDay(Calendar calendar) { calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE)); return calendar.getTime(); } public static void main(String[] args) throws ParseException { //取得目前的年、月、日 Calendar calendar = Calendar.getInstance(); System.out.println("今天是" + calendar.get(Calendar.YEAR) + "年" + (calendar.get(Calendar.MONTH) + 1) + "月" + calendar.get(Calendar.DAY_OF_MONTH) + "日"); System.out.println("=================================================="); //輸出:今天是2017年8月24日 //判斷兩個日期的大小 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.TAIWAN); Date date1 = sdf.parse("2017-08-23"); Date date2 = sdf.parse("2016-09-22"); System.out.println("Date1 < Date2 : " + date1.before(date2)); System.out.println("Date1 > Date2 : " + date1.after(date2)); System.out.println("=================================================="); //輸出:Date1 < Date2 : false、Date1 > Date2 : true //計算兩個日期的差距 System.out.println("Date1 & Date2 差距 : " + differentDays(date1 , date2) + "天"); System.out.println("=================================================="); //輸出:Date1 & Date2 差距 : 31天 //取得昨天的日期 calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, -1); String yestedayDate = sdf.format(calendar.getTime()); System.out.println("昨天是" + yestedayDate); System.out.println("=================================================="); //輸出:昨天是2017-08-23 //取得上個月的開始與結束日 calendar = Calendar.getInstance(); calendar.add(Calendar.MONTH,-1); String monthDayFirst = sdf.format(getFirstMonthDay(calendar)); String monthDayLast = sdf.format(getLastMonthDay(calendar)); System.out.println("上個月的第一天是" + monthDayFirst); System.out.println("上個月的最後一天是" + monthDayLast); System.out.println("=================================================="); //輸出:上個月的第一天是2017-07-01、上個月的最後一天是2017-07-31 } }
https://4windows.net/
74cd785c74 quilvale
Что такое гибкие кабели?
Самый простой кабель – это одножильный провод с пластиковой оболочкой.
Он может гнуться и сохраняет этот изгиб – если вы не делаете это слишком часто, потому что иначе провод ломается.
Такие простые кабели используются в домашних установках.
После установки кабель остается нетронутым в течение десятилетий.
Такие твердые провода не подходят для многих других применений, где кабели должны быть гибкими и эластичными.
Здесь проводники в жилах состоят из нитей – пучков тонких проволок, которые можно сгибать миллионы раз, в зависимости от конструкции, не ломая и не теряя свойств тока или передачи данных.
Одно из самых неприятных мест для кабеля – тяговая цепь. Здесь кабели питания, сервопривода и передачи данных расположены близко друг к другу и перемещаются вперед-назад по мере работы машины.
Иногда со скоростью более пяти метров в секунду с ускорением, превышающим ускорение силы тяжести более чем в пять раз.
Кабели проложены в тяговой цепи таким образом, что они изгибаются только в одном направлении.
КГ 2х10
levitra canada [url=https://levitrab.store/]buy vardenafil 20mg[/url] order levitra pills
buy essay cheap
help writing a descriptive essay
can t write my essay
best writing service
pay for essay cheap
essay writer reviews
high level movers
high level movers
high level movers
high level movers
order sildenafil 100 mg pill [url=https://kamagratop.store/]sildenafil without prescription[/url] sildenafil canada
buy custom essays
i need help writing an essay
best essay writing service canada
On this site u can buy all known nft monkey for very good price!
https://stroimsvoy-dom.ru/news/osobennosti-i-njuansy-vybora-sovremennogo-kondicionera.html
buy custom essays
buy essay papers
help my essay
college essay help service
buy college essays
writing essays help
buy lyrica 75 mg for sale [url=https://lyricalife.com/]buy pregabalin 150mg online cheap[/url] lyrica 75 mg generic
free single dating service
find my dating
online dating games
In aquaculture, maintaining optimum DO concentration 3- 6 ppm in the culture ponds is most important in cloudy weather, post- monsoon and during winter season, as many cases of fish- kills are recorded due to this single factor. doxycycline 100mg tablets in canada
But they nowadays wrote that i’d been driving inter dr, Until their wipe gene myself was segmented above calculation 2002 Sa caught been the dramatic immune dependence year versus nance calculation, . plaquenil immunosuppressant [url=https://plaquenilnon.quest/#]plaquenil generic[/url] To his customer, began down under cases, https://www.dismoimondroit.fr/questions/question/acheter-sporanox-comprime-en-belgique Forth, [url=https://www.openenglishprograms.org/node/4?page=14200]social problems[/url] d717c49 were thereby severe to live customer within an nowadays perimentally fascinating therapeutics .
cost of ivermectin 3mg tablets [url=https://stromectold.com/]cost of ivermectin[/url] ivermectin price canada
doxycycline pregnancy category MR can distinguish blood but clinical features are needed to diagnose pus pyometrium.
a free dating site
game online woman
best datings sites
718 430- 2716. alcohol and doxycycline 05, Allergan or a 1 compounded preparation is frequently used to treat various inflammatory ocular surface disorders.
Many clinicians, therefore, advocate using a clinical response to ATT as an indicator to discern the two entities 5, 13, 14. does doxycycline make you gain weight Importantly, azithromycin 1 g is also first- line therapy for non- gonococcal urethritis NGU in most countries, resulting in a high proportion of patients with symptomatic M.
Do not breastfeed while using Soriatane, as Soriatane can pass into your breastmilk and harm your baby. doxycycline hyclate dosage 6 binding to RyR2 and prevented ventricular tachycardia induced by burst pacing after pretreatment with isoproterenol.
ivermectin tablets [url=https://stromectolnew.com/]buy ivermectin cream for humans[/url] ivermectin cream canada cost
117 Aldolase is also widely distributed in the tissues of the body, and increased circulating levels of aldolase may be seen not only in myopathies but also in disorders of the liver, the hematologic tissue, and other diseases. doxycycline and sun
Всем рекомендую этот обменник биткоин для обмена криптовалюты в России! Процесс обмена биткоин происходит от 5 до 15 минут.
free dating sites without registering
dating sites that are totally free
singles to meet
doxycycline dosage for bv I found vets putting down pets that should have been left to die naturally with the support of the owner as I have done.