2012-03-21 192 views
0

我使用黑莓的時間選擇器&。 我想在一個字段中顯示所選日期&時間。 這是我使用的代碼。從黑莓的日期時間選擇器獲取日期和時間值

  DateTimePicker datePicker = DateTimePicker.createInstance(); 
      datePicker.doModal(); 
      Calendar cal = datePicker.getDateTime(); 
      Date date = cal.getTime(); 

回答

4
DateTimePicker dateTimePicker = DateTimePicker.createInstance(Calendar.getInstance(), null,  "HH:mm"); 

     Calendar calendar = Calendar.getInstance(); 

UiApplication.getUiApplication().invokeLater(new Runnable() {    
      public void run() { 
      if(dateTimePicker.doModal()) { 

      calendar = dateTimePicker.getDateTime(); 
      Date date = calendar.getTime(); 
      long longDate = date.getTime(); 
      SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); 
      String eventstring = dateFormat.format(date); 
      Dialog.inform("You have selected time =="+eventstring)  

     } 

    } 
}); 
+0

感謝..... BBdev ............我也用相同的代碼 – 2012-03-22 04:28:39

+0

這是FUL幫助你? – BBdev 2012-03-22 04:35:17