Converts a Calendar into a SQL timestamp. - Java java.sql

Java examples for java.sql:Timestamp

Description

Converts a Calendar into a SQL timestamp.

Demo Code

/*//  w  w  w  .j a v  a  2  s  .  c  o  m
  $Id$

  Copyright (C) 2008 Virginia Tech, Middleware.
  All rights reserved.

  SEE LICENSE FOR MORE INFORMATION

  Author:  Middleware
  Email:   middleware@vt.edu
  Version: $Revision$
  Updated: $Date$
 */
//package com.java2s;
import java.sql.Timestamp;
import java.util.Calendar;

public class Main {
    /**
     * Converts a {@link Calendar} into a SQL timestamp.
     * @param cal Calendar to convert.
     * @return Equivalent timestamp.
     */
    public static Timestamp toTimestamp(final Calendar cal) {
        final Timestamp ts = new Timestamp(cal.getTimeInMillis());
        return ts;
    }
}

Related Tutorials