在java中每天计数

编程入门 行业动态 更新时间:2024-10-25 12:22:53
本文介绍了在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关于如何使用日历/日期类型的精彩教程。 www.vogella/tutorials/JavaDateTimeAPI/article.html [ ^ ] docs.oracle/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. www.vogella/tutorials/JavaDateTimeAPI/article.html[^] docs.oracle/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中每天计数

本文发布于:2023-11-22 08:21:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616667.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!