通过TimeZone获取世界时间

时间:2014-04-23 07:52:32

标签: android datetime

我做错了什么?

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);
    }

}

1 个答案:

答案 0 :(得分:1)

这样做

        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中