java - Method which will be converted current date to next view -


i need create method next. need enter in textview project name username, curent date , time, looks one, curent date 7 15 2015, 9:58 am:

  • project_user1_7_15_2015_9_57

if curent date 9 18 2015 , time 7:15 pm, have next:

  • project_user1_9_18_2015_7_15

so have "project_user1" static, , date & time shoud take current pc , split "_"

use simpledateformat:

public string getname() {     string text = "project_user1_";     dateformat df = new simpledateformat("mm_dd_yyyy_hh_mm");     return text + df.format(new date()); } 

//passing project , user strings

public string getname(string project, string user) {      dateformat df = new simpledateformat("mm_dd_yyyy_hh_mm");      return project + "_" + user + "_" + df.format(new date()); } 

//reuse date format rather create new 1 each method call

dateformat df = new simpledateformat("mm_dd_yyyy_hh_mm");  public string getname(string project, string user, dateformat df) {     return project + "_" + user + "_" + df.format(new date()); } 

Comments