需要从电话中获取当前时间和日期,并将其发送到服务器

问题描述

| 我可以显示当前时间,但不会显示日期。我还想按下按钮并确认其被单击,并且吐司显示时间/日期的信息,然后立即返回MainActivity。 ClockInActivity.java
    import java.util.Date;
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.KeyEvent;
    import android.view.View;
    import android.widget.Button;
    import android.widget.TextView;



    public class ClockinActivity extends Activity {
        @Override
        public void onCreate(Bundle savedInstanceState) { 
            super.onCreate(savedInstanceState);
            setContentView(R.layout.clockin);
            Thread myThread = null;


            Runnable runnable = new CountDownRunner();
           myThread= new Thread(runnable);   
            myThread.start();

       }

      public void doWork() {

       runOnUiThread(new Runnable() {
           public void run() {
               try{
           TextView txtCurrentTime= (TextView)findViewById(R.id.lbltime);
                       Date dt = new Date();
                       int hours = dt.getHours();
                       int minutes = dt.getMinutes();
                       int seconds = dt.getSeconds();
                       String curTime = hours + \":\"+ minutes + \":\"+ seconds;
                       txtCurrentTime.setText(curTime);

TextView txtDateTime= (TextView)findViewById(R.id.Date);
       final Calendar c = Calendar.getInstance();
       int Year = c.get(Calendar.YEAR);
       int Month = c.get(Calendar.MONTH);
       int Day = c.get(Calendar.DAY_OF_MONTH);

           }catch (Exception e) {

           }
           }
       });

       }

       class CountDownRunner implements Runnable{
           // @Override
           public void run() {
                   while(!Thread.currentThread().isInterrupted()){
                       try {
                       doWork();
                           Thread.sleep(1000);
                       } catch (InterruptedException e) {
                               Thread.currentThread().interrupt();
                       }catch(Exception e){
                       }
                   }



    Button btn = (Button) findViewById(R.id.btn_OK);

    btn.setonClickListener(new View.OnClickListener() 
    {
        public void onClick(View view) {
            Intent data = new Intent();

          setResult(RESULT_OK,data);
            Intent i = new Intent(getApplicationContext(),Customer.class);
            startActivity(i);
            //---closes the activity---
            finish(); 
        }
    });  
    }
    }
    }
    

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)