将dateTime转换为int

时间:2012-02-28 01:20:52

标签: java android datetime int

我让用户输入日期和时间。我需要将其更改为int以适合sqlight DB。我尝试将其解析为字符串,然后解析为int,但这不起作用吗?

     Time newTime= new Time();
    newTime.hour=fmtTime.HOUR0_FIELD;
    newTime.minute=fmtTime.MINUTE_FIELD;
    newTime.monthDay=fmtDate.DAY_OF_WEEK_IN_MONTH_FIELD;
    newTime.month=fmtDate.MONTH_FIELD;
    newTime.year=fmtDate.YEAR_FIELD;
    int currentTime=newTime.get;//how would I convert newTime to an int?

2 个答案:

答案 0 :(得分:5)

currentTime = (int) (newTime.toMillis() / 1000L);

答案 1 :(得分:0)

要将Time对象转换为自纪元以来的秒数(以unix术语表示),您只需获得毫秒数:

newTime.toMillis() / 1000