Question

Basically I got some Year, Day of Year values. I would like to calculate the UTC in minutes from these values.

I tried using GregorianCalendar, but I cant get this to work. It would be nice if I just could set the YEAR and DAY_OF_YEAR fields and then let the other fields get filled out.

Or is there andy library which could help?

Was it helpful?

Solution

Is that what you want?

GregorianCalendar gc=new GregorianCalendar();
gc.set(GregorianCalendar.YEAR, 2012);
gc.set(GregorianCalendar.DAY_OF_YEAR, 32);
System.out.println(gc.getTimeInMillis()/1000/60); // /1000 -> in seconds; /60-> in minutes

System.out.println(gc.get(GregorianCalendar.DATE));
System.out.println(gc.get(GregorianCalendar.MONTH));//months are indexed from 0
System.out.println(gc.get(GregorianCalendar.YEAR));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top