在java中每天计数 [英] count per day in java

查看:292
本文介绍了在java中每天计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

各位大家好!



我是java的新手,特别是java中的Date。



我想用java来计算每天的登录次数。



例如:如果我在任何时间第一次登录它会计数= 1,如果我在没有通过计数时重新登录仍然保持= 1.但是如果我在白天过后就像登录00:00Am计数将计算= 2.



对不起我的英语很糟糕,但我希望你能理解和在这一点帮助我。



谢谢。

Hello everybody!

Im new in java, specially with Date in java.

I want to make a count login per day with java.

Ex: if im login at the first time in anytime its will count = 1, if im relogin when the day isn't pass count still keep = 1. But if im login when the day is passed like after 00:00Am count will count = 2.

Sorry about my english is so bad, but i hope you can understand and help me at this point.

Thanks.

推荐答案

请使用Calendar(aka GregorianCalendar)为此。



这是Lars Vogel关于如何使用日历/日期类型的精彩教程。



http://www.vogella.com/tutorials/JavaDateTimeAPI/article.html [ ^ ]



http://docs.oracle.com/javase/tutorial/datetime/is o / [ ^ ]



您应该将日期时间格式化为仅日期格式,并将其与上次登录时的另一个日期值进行比较。



玩得开心!
Please use Calendar ( aka GregorianCalendar) for this.

Here is a great tutorial from Lars Vogel about how to use the types Calendar/Date.

http://www.vogella.com/tutorials/JavaDateTimeAPI/article.html[^]

http://docs.oracle.com/javase/tutorial/datetime/iso/[^]

You should format the datetime to a date only format and compare it to another date value that you have from last login.

have fun!


作为TorstenH。指出,只需将当前日期与上次登录时的另一个日期值进行比较。

As TorstenH. points out, just compare the current day to another date value that you have from last login.
		Calendar lastLoginDay = //get the last login day
		Calendar currentDay = Calendar.getInstance();// current day
if (currentDay.get(Calendar.DAY_OF_YEAR) == lastLoginDay.get(Calendar.DAY_OF_YEAR)){
	//"Hey! it´s the same day!"
}else{
    	//"The day has changed!"
       //add the counter.
	lastLoginDay = Calendar.getInstance();
}


这篇关于在java中每天计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆