技巧题(时间戳计算天数)

古城微笑少年丶 2022-10-12 12:10 223阅读 0赞

目录

1 输入时间戳如20210704计算是一年的第几天


1 输入时间戳如20210704计算是一年的第几天

  1. public class calader_to_days {
  2. public int date_data(int input){
  3. int year = input / 10000;
  4. int month = input / 100 % 100;
  5. int day = input % 100;
  6. int[] days = new int[13];
  7. System.out.println(year);
  8. System.out.println(month);
  9. System.out.println(day);
  10. if((year % 4 == 0 && year % 100 != 0)||(year % 400 == 0)){
  11. //闰年判断
  12. days =new int[] {0,31,29,31,30,31,30,31,31,30,31,30,31};
  13. }else{
  14. days =new int[]{0,31,28,31,30,31,30,31,31,30,31,30,31};
  15. }
  16. int daysSum = 0;
  17. for(int i = 1 ;i < month;i ++){
  18. daysSum += days[i];
  19. }
  20. daysSum += day;
  21. return daysSum;
  22. }
  23. public static void main(String[] args) {
  24. System.out.println(new calader_to_days().date_data(20001231));
  25. }
  26. }

发表评论

表情:
评论列表 (有 0 条评论,223人围观)

还没有评论,来说两句吧...

相关阅读

    相关 优雅的时间转换技巧

    初衷 最近做了一个功能涉及到了时间戳的转换。需要对当前时间和服务器传过来的时间作比较,看差值落在哪个区间,就在页面上显示不同的文案。比如说,差值为小于1天,显示推送的是近

    相关 jQuery时间计算(转时间)

            前段时间总是碰到时间间隔计算的问题,于是自己在网上找了一些计算方法,试了下,很多都是有问题的。本篇博客是根据网上的方法自己探索出来的,亲测没问题。 话不多说,