android - How to show date manually to user when button is pressed? -


package pratyush.grapudai; import android.support.v7.app.actionbaractivity; import android.os.bundle; import android.view.view; import java.text.simpledateformat; import java.util.calendar; import java.util.date;  public class mainactivity extends actionbaractivity {      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);     }       public void submitorder(view view) {          printstandarddate(date);     }       private string printstandarddate(date date) {         return new simpledateformat("dd/mm/yy hh:mm").format(date);     }  } 

actually want show date when button pressed. using function public void buttonpressed(view view) { } there other better possible code?

you may try 1 of these alternative ways,

1. date() + simpledateformat()

 dateformat dateformat = new simpledateformat("yyyy/mm/dd hh:mm:ss");     date date = new date();     system.out.println(dateformat.format(date)); //2014/08/06 15:59:48 

2. calender() + simpledateformat()

dateformat dateformat = new simpledateformat("yyyy/mm/dd hh:mm:ss"); calendar cal = calendar.getinstance(); system.out.println(dateformat.format(cal.gettime())); //2014/08/06 16:00:22 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -