Wednesday 15 April 2015

Given a java.util.Date object, return start Date of the week -



Given a java.util.Date object, return start Date of the week -

i've requirement wherein cannot utilize jodadate/time. need utilize java.util.date , need function returns start date of week.

signature of function:

public java.util.date getweekstart(java.util.date date)

i can assume week starts on sunday. i've done plenty research solutions on jodadate. can java.util.date alone?

try next code:

public static date getweekstart(date date){ calendar c = calendar.getinstance(); c.settime(date); int dayofweek = c.get(calendar.day_of_week) - c.getfirstdayofweek(); c.add(calendar.day_of_month, -dayofweek); date firstdate = c.gettime(); homecoming firstdate; }

input current date result in next output: output :

sun oct 26 11:46:26 ist 2014

the dig on here utilize calender more on visit this link.

java date

No comments:

Post a Comment