Java examples for java.util:Year
get Time For First Day Of Year
/*/*from w ww . j av a 2 s .com*/ * Copyright 2009 Yodlee, Inc. All Rights Reserved. Your use of this code * requires a license from Yodlee. Any such license to this code is * restricted to evaluation/illustrative purposes only. It is not intended * for use in a production environment, and Yodlee disclaims all warranties * and/or support obligations concerning this code, regardless of the terms * of any other agreements between Yodlee and you." */ //package com.java2s; import java.util.Calendar; public class Main { public static void main(String[] argv) throws Exception { Calendar calendar = Calendar.getInstance(); System.out.println(getTimeForFirstDayOfYear(calendar)); } public static Long getTimeForFirstDayOfYear(Calendar calendar) { Calendar tempCalendar = (Calendar) calendar.clone(); setTimeAsFirstDayOfYear(tempCalendar); return new Long(tempCalendar.getTimeInMillis()); } public static void setTimeAsFirstDayOfYear(Calendar calendar) { calendar.set(Calendar.DAY_OF_YEAR, 1); normalise(calendar); } public static void normalise(Calendar calendar) { Calendar tempCalendar = (Calendar) calendar.clone(); calendar.clear(); calendar.set(Calendar.YEAR, tempCalendar.get(Calendar.YEAR)); calendar.set(Calendar.DAY_OF_YEAR, tempCalendar.get(Calendar.DAY_OF_YEAR)); } }