Here you can find the source of convertToSDate(java.util.Date uDate)
Parameter | Description |
---|---|
uDate | java.util.Date |
public static java.sql.Date convertToSDate(java.util.Date uDate)
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; public class Main { /**/*from w ww.ja v a 2 s .c o m*/ * <h1>convertToSDate</h1> Chuyen ngay kieu java.util.Date thanh * java.sql.Date * * @param uDate * java.util.Date * @return sDate - java.sql.Date hoac null */ public static java.sql.Date convertToSDate(java.util.Date uDate) { if (uDate == null) { return null; } else { java.sql.Date sDate = new java.sql.Date(uDate.getTime()); return sDate; } } /** * <h1>convertToSDate</h1> Chuyen String dinh dang "dd/MM/yyyy" thanh ngay * kieu java.sql.Date * * @param dateInString * String * @return uDate - java.sql.Date hoac null */ public static java.sql.Date convertToSDate(String dateInString) { if (dateInString == null) { return null; } else { SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); java.util.Date uDate = null; java.sql.Date sDate = null; try { uDate = dateFormat.parse(dateInString); sDate = new java.sql.Date(uDate.getTime()); } catch (ParseException e) { return null; } return sDate; } } }