Java Timestamp Parse stripToMinutes(java.sql.Timestamp timestamp)

Here you can find the source of stripToMinutes(java.sql.Timestamp timestamp)

Description

Call this function to round off the second and millisecond of time.

License

Open Source License

Parameter

Parameter Description
timestamp The timestamp value to be strip to minutes

Declaration


public static java.sql.Timestamp stripToMinutes(java.sql.Timestamp timestamp) 

Method Source Code

//package com.java2s;
/*//from w  w w  .  ja  v a2s.  c om
* @(#)Utility.java
*
* Copyright (c) 2003 DCIVision Ltd
* All rights reserved.
*
* This software is the confidential and proprietary information of DCIVision
* Ltd ("Confidential Information").  You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with DCIVision Ltd.
 */

import java.util.Calendar;

public class Main {
    /**
      * Call this function to round off the second and millisecond of time.
      *
      * @param timestamp               The timestamp value to be strip to minutes
      * @return
      */

    public static java.sql.Timestamp stripToMinutes(java.sql.Timestamp timestamp) {
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(timestamp.getTime());
        int day = cal.get(Calendar.DATE);
        int month = cal.get(Calendar.MONTH);
        int year = cal.get(Calendar.YEAR);
        int hour = cal.get(Calendar.HOUR_OF_DAY);
        int time = cal.get(Calendar.MINUTE);

        cal.clear();
        cal.set(year, month, day, hour, time);
        timestamp = new java.sql.Timestamp(cal.getTimeInMillis());
        return timestamp;
    }
}

Related

  1. stringToTimestamp(String marcTimestamp)
  2. stringToTimestamp(String sTimestamp)
  3. stringToTimestamp(String ts)
  4. stringToTimestamp(String value)
  5. stringToTimesTamp(String yMd, boolean isEndTime)