gpt4 book ai didi

android - 将毫秒与android中的数据进行比较

转载 作者:太空狗 更新时间:2023-10-29 14:24:26 26 4
gpt4 key购买 nike

我在 毫秒 中将 data+time 保存在数据库 (sq lite) 中,现在我想要从特定日期的 sql-lite 获取数据,我的日期格式为“26-December-2012”,如何将其与毫秒进行比较。

从数据库中获取数据的查询应该是什么?

最佳答案

你必须将毫秒转换成日期格式然后比较两个日期

转换成日期格式

        public static String getDate(long milliSeconds, String dateFormat)
{`enter code here`
// Create a DateFormatter object for displaying date in specified format.
DateFormat formatter = new SimpleDateFormat(dateFormat);

// Create a calendar object that will convert the date and time value in milliseconds to date.
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(milliSeconds);
return formatter.format(calendar.getTime());
}

比较日期

SimpleDateFormat curFormater = new SimpleDateFormat("dd/MM/yyyy"); 
Date date1 = curFormater.parse(date1Str);
Date date2 = curFormater.parse(date2Str);
if (date1.before(date2))
{
}

关于android - 将毫秒与android中的数据进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13774935/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com