Java getter and setter for a date field -


i beginning java , have been ask write class mydate. such class has fields year, month , day.

i should use following syntax set date:

setdate(long timeelapsed) 

i know can following:

date tempdate = new date(); long lngdate = tempdate.gettime(); system.out.println("lngdate: " + lngdate); 

how calculate "long timeelapsed" parameter given year, month , day?

now, should use gregoriancalendar display date, have done following:

gregoriancalendar cal = new gregoriancalendar(year, month, day); system.out.println("year: " + cal.year); system.out.println("month: " + cal.month); system.out.println("day: " + cal.day_of_month); 

but results follow:

year: 1 month: 2 day: 5 

how can use gregoriancalendar display date in mydate class? have been working on issue while without success.

i appreciate feedback.

respectfully,
jorge maldonado

calendar.year month , day_of_the_month constants use in get() method. so

system.out.println("year: " + cal.get(calendar.year)); system.out.println("month: " + cal.get(calendar.month)); system.out.println("day: " + cal.get(calendar.day_of_month)); 

does need.

btw on top not need create new date time value:

long lngdate = system.currenttimemillis(); system.out.println("lngdate: " + lngdate); 

value same. when new date created uses system.currenttimemillis()

ps. keep in mind cal.get(calendar.month) returns month number -1. jan month 0, feb month 1 , on.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -