Java examples for java.util:Month
This method takes time in milliseconds ,and returns a Calendar object with only year and month fields set to the given time.
/*/*ww w. ja v a 2 s .c o m*/ * 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 { long timeMillis = 2; System.out.println(getNormalizedMonth(timeMillis)); } /** * This method takes time in milliseconds ,and returns a Calendar object with * only year and month fields set to the given time. Date is set to the * first day of the month.Rest of the fields in caledar are cleared. * * @param timeMillis * @return */ public static Calendar getNormalizedMonth(long timeMillis) { Calendar transCalendar = Calendar.getInstance(); transCalendar.setTimeInMillis(timeMillis); Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.set(Calendar.YEAR, transCalendar.get(Calendar.YEAR)); calendar.set(Calendar.MONTH, transCalendar.get(Calendar.MONTH)); calendar.set(Calendar.DAY_OF_MONTH, 1); return calendar; } }