Code example for Timestamp

Methods: getNanos, toString

0
        rv.setFractionalSecond(null);
        return rv.normalize();
    } 
 
    public static XMLGregorianCalendar fromTimestamp(Timestamp in) throws DatatypeConfigurationException {
        int nanos = in.getNanos();
        if (nanos % TimeUnit.MILLISECONDS.toNanos(1) != 0)
            throw new RuntimeException(in.toString()); // panic if unecessary loss of precision, see: http://stackoverflow.com/q/19756952/274677
        else 
            return dateToXMLGregorian(in);
    } 
 
 
    // see http://stackoverflow.com/q/835889/274677  
    // for the following two methods 
    public static XMLGregorianCalendar dateToXMLGregorian(Date d) throws DatatypeConfigurationException {
        GregorianCalendar c = new GregorianCalendar();
        c.setTime(d);
        return DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
    }