java - Incorrect output after converting to SqlDate -
this question has answer here:
import java.text.parseexception; import java.text.simpledateformat; import java.util.date; public class test { /** * @param args */ public static void main(string[] args) { simpledateformat formatter = new simpledateformat("yyyy-mm-dd"); string dateinstring = "2016-04-23"; try { date date = formatter.parse(dateinstring); java.sql.date sqldate = new java.sql.date(date.gettime()); system.out.println("date: -- "+date); system.out.println("formatterdate : -- "+formatter.format(date)); system.out.println("sqldate : -- "+sqldate); } catch (parseexception e) { e.printstacktrace(); } } }
output :
date: -- sat jan 23 00:04:00 cst 2016 formatterdate : -- 2016-04-23 sqldate : -- 2016-01-23
my out put should 2016-04-23 not 2016-01-23
as per javadocs
m minute in hour
you want
m month in year
Comments
Post a Comment