Search code examples
androidandroid-timepicker

how to initialize Time variable android


i searched a lot to find how initialize Time variables in my Android project, i have tried to use Set(); methode but doesn't work, i need your help thank's ` here is my source code :

TableRow tableRow;
Time HourProgram;
int H = 12000, M = 1200;
int averageConsultationTime = 30;

// String
// TableSettinHourgHeader=""+HourBegen+"H"+averageConsultationTime+"|"
// +HourBegen+"H"+averageConsultationTime+"|"
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.table);
    Log.i("OK", "onCreateOK");

    Log.i("OK", "HMOK");
    TextView DynamicButton = new TextView(MainActivity.this);

    tableRow = (TableRow) findViewById(R.id.tr1);

    LayoutParams layoutparams = new TableRow.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    DynamicButton.setLayoutParams(layoutparams);
    String ss = converteur(H, M);
    Log.i("OK", "converteur(H, M)OK" + ss);
    DynamicButton.setText("Assalam Aleikum " + ss);
    Log.i("OK", "setTextOK" + ss);
    tableRow.addView(DynamicButton);

}

@SuppressWarnings("unused")
private String converteur(int timeBegen, int averageConsultationTime) {

    String sTb = "" + String.valueOf(timeBegen).toString();
    String sAct = ""
            + String.valueOf(this.averageConsultationTime).toString();

    // Toast.makeText(this,
    // ""+timeBegen+"H"+averageConsultationTime,Toast.LENGTH_LONG);

    return "timeBegen : " + sTb + " averageConsultationTime : "
            + averageConsultationTime;

}

`


Solution

  • For

    java.sql.Time

    It should be

    Time HourProgram = new Time(System.currentTimeMillis());
    

    Also, if you prefer Calendar then,

    Time HourProgram = new Time(Calendar.getInstance().getTimeInMillis());