android - Why my date is not of current day but shows that of 1970? -


my code:

date p_selected = new simpledateformat("hh:mm", locale.us)                         .parse(string.valueof(p_hour[0]) + ":" + string.valueof(p_min[0])); log.d("ttt", "current_time = " + calender.gettime() + "user time = " + p_selected); 

this log current time of 2015 , why user time 1970?

current_time = wed sep 30 11:35:43 gmt+05:30 2015   user time = thu jan 01 11:02:00 gmt+05:30 1970. 

anything missing here?

try this,

first way,

simpledateformat sdf = new simpledateformat("yyyymmdd_hhmmss"); string currentdateandtime = sdf.format(new date()); tv.settext(currentdateandtime); 

second way,

tvdisplaydate = (textview) findviewbyid(r.id.tvdate);       final calendar c = calendar.getinstance();     yy = c.get(calendar.year);     mm = c.get(calendar.month);     dd = c.get(calendar.day_of_month);      // set current date textview     tvdisplaydate.settext(new stringbuilder()     // month 0 based, add 1             .append(yy).append(" ").append("-").append(mm + 1).append("-")             .append(dd)); 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -