List of usage examples for java.util Calendar MILLISECOND
int MILLISECOND
To view the source code for java.util Calendar MILLISECOND.
Click Source Link
get
and set
indicating the millisecond within the second. From source file:Main.java
/** * Get a Calendar for this gdate, or ndef in case of failure * @param gdate/* www . ja v a 2 s . co m*/ * @param def * @return */ public static Calendar getCalendar(String gdate, Calendar def) { if ((gdate != null) && (gdate.length() < 14)) gdate = gdate + "00000000000000"; if ((gdate == null) || (gdate.length() < 14)) { return def; } Calendar date = CalendargetInstance(); try { date.set(Integer.parseInt(gdate.substring(0, 4)), Integer.parseInt(gdate.substring(4, 6)) - 1, Integer.parseInt(gdate.substring(6, 8)), Integer.parseInt(gdate.substring(8, 10)), Integer.parseInt(gdate.substring(10, 12)), Integer.parseInt(gdate.substring(12, 14))); date.set(Calendar.MILLISECOND, Integer.parseInt(gdate.substring(15, 18))); } catch (Exception e) { return def; } //System.out.println("getCalendar "+gdate+" into "+date); return date; }
From source file:com.bstek.dorado.core.el.ExpressionUtilsObject.java
public java.util.Date getToday() { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); return calendar.getTime(); }
From source file:Main.java
public static void moveToCalendarMillisecond(Calendar cal, int millisecond) { assertArgumentNotMinusInteger("millisecond", millisecond); cal.set(Calendar.MILLISECOND, millisecond); }
From source file:fll.web.report.finalist.FinalistDBRow.java
@JsonIgnore public Date getTime() { final Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR, getHour()); cal.set(Calendar.MINUTE, getMinute()); cal.set(Calendar.SECOND, 0);/* w w w . ja va2 s . co m*/ cal.set(Calendar.MILLISECOND, 0); return cal.getTime(); }
From source file:Main.java
/** * Adds a number of milliseconds to a date returning a new object. * The original date object is unchanged. * * @param date the date, not null/*w w w .j a va 2 s . co m*/ * @param amount the amount to add, may be negative * @return the new date object with the amount added * @throws IllegalArgumentException if the date is null */ public static Date addMilliseconds(Date date, int amount) { return add(date, Calendar.MILLISECOND, amount); }
From source file:Main.java
/** * Sets the miliseconds field to a date returning a new object. * The original date object is unchanged. * * @param date the date, not null/*from ww w. ja v a 2s . c o m*/ * @param amount the amount to set * @return a new Date object set with the specified value * @throws IllegalArgumentException if the date is null * @since 2.4 */ public static Date setMilliseconds(Date date, int amount) { return set(date, Calendar.MILLISECOND, amount); }
From source file:facebook4j.internal.util.z_F4JInternalStringUtilTest.java
@Test public void formatISO8601Datetime() throws Exception { Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, 2012); cal.set(Calendar.MONTH, 5);//from w w w. j a va2s . c o m cal.set(Calendar.DAY_OF_MONTH, 15); cal.set(Calendar.HOUR_OF_DAY, 16); cal.set(Calendar.MINUTE, 17); cal.set(Calendar.SECOND, 18); cal.set(Calendar.MILLISECOND, 0); cal.setTimeZone(TimeZone.getTimeZone("JST")); String actual1 = z_F4JInternalStringUtil.formatISO8601Datetime(cal); assertThat(actual1, is("2012-06-15T16:17:18+0900")); cal.setTimeZone(TimeZone.getTimeZone("UTC")); String actual2 = z_F4JInternalStringUtil.formatISO8601Datetime(cal); assertThat(actual2, is("2012-06-15T07:17:18+0000")); //16-9=7 JSONObject json = new JSONObject( "{\"datetime1\": \"" + actual1 + "\", \"datetime2\": \"" + actual2 + "\"}"); Date d1 = z_F4JInternalParseUtil.getISO8601Datetime("datetime1", json); Date d2 = z_F4JInternalParseUtil.getISO8601Datetime("datetime2", json); assertThat(d1, is(d2)); }
From source file:com.aw.core.db.DbUtil.java
public boolean hasOnlyDateInfo(Date date) { Calendar cal = new GregorianCalendar(); cal.setTime(date);//from w w w .j av a2 s .c o m if (cal.get(Calendar.HOUR_OF_DAY) != 0) return false; if (cal.get(Calendar.MINUTE) != 0) return false; if (cal.get(Calendar.SECOND) != 0) return false; if (cal.get(Calendar.MILLISECOND) != 0) return false; return true; }
From source file:com.indoqa.lang.util.TimeUtilsTest.java
@Test public void formatDate() { Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("GMT+1")); calendar.set(2012, 2, 1, 10, 5, 30); calendar.set(Calendar.MILLISECOND, 501); assertEquals("2012-03-01 09:05:30.501", TimeUtils.formatDate(calendar.getTime())); }
From source file:Main.java
/** * Creates a Calendar instance for the given year, month (1-based), day * (1-based), hour, minute and second in the given time zone *///from w ww. j a va 2s . c o m public static Calendar createDate(TimeZone timeZone, int year, int month, int day, int hour, int minute, int second) { Calendar date = Calendar.getInstance(timeZone); date.set(year, month - 1, day, hour, minute, second); // Months start at 0 for Calendar! date.set(Calendar.MILLISECOND, 0); return date; }