Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I convert year and week to Java Date object?

Tags:

java

datetime

How can I convert year and week to Java Date object? I'm using JodaTime, but standard Java classes using solution is fine too.

like image 951
newbie Avatar asked Apr 21 '11 06:04

newbie


1 Answers

Solution using standard java classes. This just gets the current time and sets the fields of year and week of year to known values.

Calendar cld = Calendar.getInstance();
cld.set(Calendar.YEAR, year);
cld.set(Calendar.WEEK_OF_YEAR, week);
Date result = cld.getTime();
like image 76
Vladimir Ivanov Avatar answered Sep 22 '22 12:09

Vladimir Ivanov