Java SQL Time From getDatetime(String value)

Here you can find the source of getDatetime(String value)

Description

Helper to create a date-time given a string of the form yyyy-mm-dd hh:mm:ss.

License

Open Source License

Parameter

Parameter Description
value the value. May be null

Return

the corresponding date-time or null if value is null

Declaration

public static Date getDatetime(String value) 

Method Source Code

//package com.java2s;
/*//  ww  w .  jav a  2  s .  c  o m
 * Version: 1.0
 *
 * The contents of this file are subject to the OpenVPMS License Version
 * 1.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.openvpms.org/license/
 *
 * Software distributed under the License is distributed on an 'AS IS' basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * Copyright 2015 (C) OpenVPMS Ltd. All Rights Reserved.
 */

import java.sql.Timestamp;

import java.util.Date;

public class Main {
    /**
     * Helper to create a date-time given a string of the form
     * <em>yyyy-mm-dd hh:mm:ss</em>.
     *
     * @param value the value. May be {@code null}
     * @return the corresponding date-time or {@code null} if {@code value} is null
     */
    public static Date getDatetime(String value) {
        return value != null ? new Date(Timestamp.valueOf(value).getTime()) : null; // use Date, for easy comparison
    }
}

Related

  1. getDateTime(ResultSet rs, String field, Calendar cal)
  2. getDateTime(String dateTime)
  3. getDateTime(String s)
  4. getDateTimeBySecond(long timeMillis)
  5. getDateTimeFormat()
  6. getDateTimeRtnTime(Date date, String time)
  7. getDateTimeStr(Date date)