Here you can find the source of millisecondOf(Date date)
Parameter | Description |
---|---|
date | the date to extract the millisecond from - must not be null. |
Parameter | Description |
---|---|
NullPointerException | if given Date is null |
public static int millisecondOf(Date date)
//package com.java2s; /**//ww w . j av a 2 s . c om * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * Copyright 2012-2016 the original author or authors. */ import java.util.Calendar; import java.util.Date; public class Main { /** * Extracts the millisecond of the given Date. * * @param date the date to extract the millisecond from - must not be null. * @return the millisecond of the given Date * @throws NullPointerException if given Date is null */ public static int millisecondOf(Date date) { return toCalendar(date).get(Calendar.MILLISECOND); } /** * Converts the given Date to Calendar, returns null if the given Date is null. * * @param date the date to convert to a Calendar. * @return the Calendar corresponding to the given Date or null if the given Date is null. */ public static Calendar toCalendar(Date date) { if (date == null) { return null; } Calendar calendar = Calendar.getInstance(); calendar.setTime(date); return calendar; } }