— Scott McNealy, Sun Microsystems Chairman, President and ceo


Dates and Times can be incremented



Download 40,57 Mb.
Pdf ko'rish
bet289/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   285   286   287   288   289   290   291   292   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

Dates and Times can be incremented - The Calendar class has methods that 
allow you to add and subtract values from various fields, for example “add 
one to the month”, or “subtract three years”.
ß
Dates and Times can be represented in milliseconds - The Calendar class 
lets you convert your dates into and out of a millisecond representation. 
(Specifically, the number of milliseconds that have occured since January 
1st, 1970.) This allows you to perform precise calculations such as “elapsed 
time between two times” or “add 63 hours and 23 minutes and 12 seconds 
to this time”.
An example of working with a Calendar object:
Calendar c = Calendar.getInstance();
 c.set(2004,0,7,15,40);
long day1 = 
c.getTimeInMillis();
day1 += 1000 * 60 * 60;
c.setTimeInMillis(day1)
;
System.out.println(“new hour “ + 
c.get(c.HOUR_OF_DAY)
);
c.add(c.DATE, 35);
System.out.println(“add 35 days “ + 
c.getTime()
);
c.roll(c.DATE, 35);
System.out.println(“roll 35 days “ + 
c.getTime()
);
 c.set(c.DATE, 1);
System.out.println(“set to 1 “ + 
c.getTime()
);
File Edit Window Help Time-Flies
new hour 16
add 35 days Wed Feb 11 16:40:41 MST 2004
roll 35 days Tue Feb 17 16:40:41 MST 2004
set to 1 Sun Feb 01 16:40:41 MST 2004
Convert this to a big ol’ 
amount of milliseconds.
Set time to Jan. 7, 2004 at 15:40. 
(Notice the month is zero-based.)
Add 35 days to the date, which 
should move us into February.
“Roll” 35 days onto this date. This 
“rolls” the date ahead 35 days, but 
DOES NOT change the month!
We’re not incrementing here, just 
doing a “set” of the date.
Add an hour’s worth of millis, then update the time.
(Notice the “+=”, it’s like day1 = day1 + ...). 
This output confirms how millis, 
add, roll, and set work.



Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   285   286   287   288   289   290   291   292   ...   555




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish