Java XML Date to GetDateDiffInDays(XMLGregorianCalendar Calendar)

Here you can find the source of GetDateDiffInDays(XMLGregorianCalendar Calendar)

Description

Get Date Diff In Days

License

Apache License

Declaration

public static long GetDateDiffInDays(XMLGregorianCalendar Calendar) 

Method Source Code

//package com.java2s;
/* /*from w w w .ja va2  s .  co m*/
 * CTS2 based Terminology Server and Terminology Browser
 * Copyright (C) 2014 FH Dortmund: Peter Haas, Robert Muetzner
 *
 * 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.
 */

import java.util.Date;

import javax.xml.datatype.XMLGregorianCalendar;

public class Main {
    public static long GetDateDiffInDays(XMLGregorianCalendar Calendar) {
        if (Calendar == null)
            return -1;

        /** The date at the end of the last century */
        Date d1 = Calendar.toGregorianCalendar().getTime();

        /** Today's date */
        Date today = new Date();

        if (today.after(d1))
            return -1;

        // Get msec from each, and subtract.
        long diff = d1.getTime() - today.getTime();

        return (diff / (1000 * 60 * 60 * 24)) + 1;
        //System.out.println("The 21st century (up to " + today + ") is "
        //    + (diff / (1000 * 60 * 60 * 24)) + " days old.");
    }
}

Related

  1. convertXMLGregorianCalendarToDate(XMLGregorianCalendar xmlGregorianCalendar)
  2. convertXMLGregorianCalendarToDate(XMLGregorianCalendar xmlGregorianCalendar)
  3. ConvertXMLGregorianCalenderToString(XMLGregorianCalendar Calendar, String Format)
  4. getDate(XMLGregorianCalendar calendar)
  5. getDate(XMLGregorianCalendar calendar)
  6. getDateFromXmlGregorianCalendar(XMLGregorianCalendar da)
  7. getDateFromXMLGregorianCalendar(XMLGregorianCalendar xmlCalendar)
  8. getDateFromXMLGregorianCalendar(XMLGregorianCalendar xmlGregorianCalendar)
  9. getDurationFromCalendar( final XMLGregorianCalendar cal)