通过时区获取世界时间



我做错了什么?

import java.util.Calendar;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity implements OnClickListener{
Button b;
EditText t;

@Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    b=(Button)findViewById(R.id.button1);
    t=(EditText)findViewById(R.id.editText1);
    b.setOnClickListener(this);
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
    }
    @Override
public void onClick(View arg0) {
    Calendar cal = Calendar.getInstance();
    TimeZone tz = cal.getTimeZone();
    String Name=t.getText().toString().trim();
    tz.setID(Name);
    }
}

这样做

        Calendar calender = Calendar.getInstance(TimeZone.getTimeZone("EST"));
        System.out.println("Day of week: " + calender.get(Calendar.DAY_OF_WEEK)); //2 is monday
        System.out.println("Day of the month: " + calender.get(Calendar.DAY_OF_MONTH));
        System.out.println("Month: " + calender.get(Calendar.MONTH)); //0 is january 3 is april
        System.out.println("Year: " + calender.get(Calendar.YEAR));
        System.out.println("Hour: " + calender.get(Calendar.HOUR_OF_DAY));
        System.out.println("Minutes: " + calender.get(Calendar.MINUTE));

在设置GMT、EST等的getTimeZone中。

相关内容

  • 没有找到相关文章