如何使用日期编号获取系统日期

时间:2014-08-21 09:26:19

标签: android

我想获取当前系统日期,并根据我需要一年中的特定日期编号。请帮助得到相同的。

Ex:03-04-2014(dd-mm-yyyy) 我需要一个醋栗日期= 03-04-2014 和一年中的某一天=一年中的第62天。

以下是我的逻辑在Android SDK中的外观。我

package com.kli.utilizationcalci;
public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final EditText editTargethoursyear = (EditText) findViewById(R.id.editTargethoursyear);
        final EditText editDesignatedholidays = (EditText) findViewById(R.id.editDesignatedholidays);
        final EditText editMaxvacationsavailable = (EditText) findViewById(R.id.editMaxvacationsavailable);
        final EditText editHourstilldate = (EditText) findViewById(R.id.editHourstilldate);
        final EditText editVacationsavailed = (EditText) findViewById(R.id.editVacationsavailed);
        final EditText editVacationsplanned = (EditText) findViewById(R.id.editVacationsplanned);
        final EditText editHoursplannedperweek = (EditText) findViewById(R.id.editHoursplannedperweek);
        final EditText editIfsamevacationsminhoursforweek = (EditText) findViewById(R.id.editIfsamevacationsminhoursforweek);
        final EditText editIfsamehoursplannedvacationsavailable = (EditText) findViewById(R.id.editIfsamehoursplannedvacationsavailable);
        Button buttonCalculate = (Button) findViewById(R.id.buttonCalculate);

    buttonCalculate.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                double Targethoursyear = Double.valueOf( editTargethoursyear.getText().toString());
                double Designatedholidays = Double.valueOf( editDesignatedholidays.getText().toString());
                double Maxvacationsavailable = Double.valueOf( editMaxvacationsavailable.getText().toString());
                double Hourstilldate = Double.valueOf( editHourstilldate.getText().toString());
                double Vacationsavailed = Double.valueOf( editVacationsavailed.getText().toString());
                double Vacationsplanned = Double.valueOf( editVacationsplanned.getText().toString());
                double Hoursplannedperweek = Double.valueOf( editHoursplannedperweek.getText().toString());
                double Totalvacations = Vacationsavailed + Vacationsplanned + Designatedholidays;
                double Ifsamevacationsminhoursforweek = 1+1;

                editIfsamevacationsminhoursforweek.setText(String.valueOf(Ifsamevacationsminhoursforweek));
                double Ifsamehoursplannedvacationsavailable = 2+2;

                editIfsamehoursplannedvacationsavailable.setText(String.valueOf(Ifsamehoursplannedvacationsavailable));
            }
        });
    }
}

2 个答案:

答案 0 :(得分:2)

  int dayOfYear = Calendar.getInstance().get(Calendar.DAY_OF_YEAR);

答案 1 :(得分:0)

您可以像这样获取日期,并以您希望的格式显示日期,如果您需要更多帮助,请查看此内容。 http://developer.android.com/reference/java/util/Calendar.html

        mYear = c.get(Calendar.YEAR);
        mMonth = c.get(Calendar.MONTH);
        mDay = c.get(Calendar.DAY_OF_MONTH);
    mDateDisplay.setText(new StringBuilder().append(mMonth).append("-").append(mDay).append("-").append(mYear).append(" "));