jsp - how can i format the java.sql.Date to MM/dd/yyyy -


my code is

final long millis_in_a_day = 1000*60*60*24; date yesterdaydate= new java.sql.date(new java.util.date().gettime() - millis_in_a_day); out.println(yesterdaydate); 

the output getting in format yyyy/mm/dd..how can in mm/dd/yyyy

please don't . date using date object , parse using simpledateformat . simple . don't go hard coding value. not convenient programmer . please find code

date date  = new date();//today date simpledateformat format = new simpledateformat("mm/dd/yyyy");// format in format or change change  string format= format.format(date); system.out.println(format);// 01/06/2016 

or

calendar todaydate = calendar.getinstance(); todaydate.add(calendar.day_on_month, -1);//import java.util.* date yesterday = cal.gettime(); simpledateformat format = new simpledateformat("mm/dd/yyyy"); string format = format.format(yesterday); system.out.println(format);// 01/06/2016 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -