Here you can find the source of roundSmallDateTimeValue(Object value)
Parameter | Description |
---|---|
value | a parameter |
public static Object roundSmallDateTimeValue(Object value)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; public class Main { /**/*w ww .j a v a 2s. c o m*/ * Utility method for a datetime value * * @param value * @return */ public static Object roundSmallDateTimeValue(Object value) { if (value == null) { return null; } Calendar cal; java.sql.Timestamp ts = null; int nanos = -1; if (value instanceof Calendar) { cal = (Calendar) value; } else { ts = (java.sql.Timestamp) value; cal = Calendar.getInstance(); cal.setTimeInMillis(ts.getTime()); nanos = ts.getNanos(); } // round to the nearest minute double seconds = cal.get(Calendar.SECOND) + (nanos == -1 ? ((double) cal.get(Calendar.MILLISECOND) / 1000) : ((double) nanos / 1000000000)); if (seconds > 29.998) { cal.set(Calendar.MINUTE, cal.get(Calendar.MINUTE) + 1); } cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); nanos = 0; // required to force computation cal.getTimeInMillis(); // return appropriate value if (value instanceof Calendar) { return cal; } else { ts.setTime(cal.getTimeInMillis()); ts.setNanos(nanos); return ts; } } }