Code:

        public List<DateTime> getMissDateData()
{ DateTime[] keys = { DateTime.Now.AddDays(-5), DateTime.Now.AddDays(-3), DateTime.Now.AddDays(-1), };
List<DateTime> missingDate = new List<DateTime>();
for (int i = 0; i < keys.Length; i++)
{
logger.Info("Orginal data:"+keys[i]);
} if (keys.Length > 0)
{
DateTime firstDate = keys[0];
if (firstDate.Day > 1)
{
int missingDateInt = firstDate.Day - 1;
for (int i = missingDateInt; i > 0; i--)
{
missingDate.Add(firstDate.AddDays(-i));
}
}
int keysLength = (keys[keys.Length - 1] - keys[0]).Days; DateTime dtTemp = keys[0];
// firstDate = keys[0];
int count = keys.Length;
for (int i = 0; i < count; i++)
{
Console.WriteLine(dtTemp.ToString(keys[i].ToString("yyyy-MM-dd HH:mm:ss")));
while (DateTime.Compare(keys[i], dtTemp) != 0)
{
logger.InfoFormat("Actual Date:{0}; The date of the cumulative:{1}", keys[i].ToShortDateString(), dtTemp.ToShortDateString());
logger.InfoFormat("{0}", DateTime.Compare(keys[i], dtTemp));
//Console.WriteLine(String.Format("Actual Date:{0}; The date of the cumulative:{1}", keys[i].ToShortDateString(), dtTemp.ToShortDateString()));
// Console.WriteLine(String.Format("{0}", DateTime.Compare(keys[i], dtTemp)));
missingDate.Add(dtTemp);
dtTemp = dtTemp.AddDays(1);
}
dtTemp = dtTemp.AddDays(1);
}
}
else
{
logger.InfoFormat("Has no new data:{0}", keys.Length);
// Console.WriteLine(String.Format("Has no new data:{0}", keys.Length));
} for (int i = 0; i < missingDate.Count; i++)
{
logger.Info("Missing data:" + missingDate[i].ToShortDateString());
//Console.WriteLine("Missing data:" + missingDate[i].ToShortDateString());
}
return missingDate;
}
欢迎大家吐槽。

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

查找正序排列的List中缺失的日期数据的一个算法的更多相关文章

  1. oracle 中从一个历史表中查询最新日期数据插入到另一个表中语句

    先从历史表中查询最新的一个语句: select t.id from ( select r.*, row_number() over(partition by r.分组字段 order by r.排序时 ...

  2. 洛谷 P1030 求先序排列 Label:None

    题目描述 给出一棵二叉树的中序与后序排列.求出它的先序排列.(约定树结点用不同的大写字母表示,长度<=8). 输入输出格式 输入格式: 2行,均为大写字母组成的字符串,表示一棵二叉树的中序与后序 ...

  3. C#数组的排序(正序逆序)

    C#数组的排序(正序逆序) 这种排序 超级简单的 ! using System; using System.Collections.Generic; using System.Linq; using ...

  4. 《剑指offer》第五十三题(0到n-1中缺失的数字)

    // 面试题53(二):0到n-1中缺失的数字 // 题目:一个长度为n-1的递增排序数组中的所有数字都是唯一的,并且每个数字 // 都在范围0到n-1之内.在范围0到n-1的n个数字中有且只有一个数 ...

  5. indexOf() 如何判断一个元素在指定数组中是否存在? 找出指定元素出现的所有位置? indexOf()方法 是正序查找,lastIndexOf()是倒叙查找

    indexOf()方法返回在数组中可以找到一个给定元素的第一个索引,如果不存在,则返回-1. let a = [2, 9, 7, 8, 9]; a.indexOf(2); // 0 a.indexOf ...

  6. 转<<C#集合Dictionary中按值的降序排列

    转载地址:http://blog.sina.com.cn/s/blog_5c5bc9070100pped.html C#集合Dictionary中按值的降序排列 static void Main(st ...

  7. 给定一个只包含正整数的非空数组,返回该数组中重复次数最多的前N个数字 ,返回的结果按重复次数从多到少降序排列(N不存在取值非法的情况)

    """ #给定一个只包含正整数的非空数组,返回该数组中重复次数最多的前N个数字 #返回的结果按重复次数从多到少降序排列(N不存在取值非法的情况) 解题思路: 1.设定一个 ...

  8. SQL-27 给出每个员工每年薪水涨幅超过5000的员工编号emp_no、薪水变更开始日期from_date以及薪水涨幅值salary_growth,并按照salary_growth逆序排列。 提示:在sqlite中获取datetime时间对应的年份函数为strftime('%Y', to_date)

    题目描述 给出每个员工每年薪水涨幅超过5000的员工编号emp_no.薪水变更开始日期from_date以及薪水涨幅值salary_growth,并按照salary_growth逆序排列. 提示:在s ...

  9. SQL-15 查找employees表所有emp_no为奇数,且last_name不为Mary的员工信息,并按照hire_date逆序排列

    题目描述 查找employees表所有emp_no为奇数,且last_name不为Mary的员工信息,并按照hire_date逆序排列CREATE TABLE `employees` (`emp_no ...

随机推荐

  1. CentOS7 关闭防火墙[转]

    CentOS6关闭防火墙使用以下命令, /临时关闭 service iptables stop //禁止开机启动 chkconfig iptables off CentOS7中若使用同样的命令会报错, ...

  2. JavaScript 用new创建对象的过程

       在JavaScript中创建自定义对象都需要用new运算符,那么创建对象的过程是什么样的呢? 例如现在有如下构造函数: function Person(name) { this.name = n ...

  3. APIO2012 派遣dispatching | 左偏树

    题目链接:戳我 就是尽可能地选取排名小的,加起来就可以了.然后我们考虑利用一个大根堆,一个一个合并,如果超过派遣的钱,我们就把费用最大的那个忍者丢出队列. 左偏树,作为一个十分优秀的可并堆,我们这道题 ...

  4. 4.client、offset、scroll系列

    client.offset.scroll系列 他们的作用主要与计算盒模型.盒子的偏移量和滚动有关 clientTop 内容区域到边框顶部的距离 ,说白了,就是边框的高度 clientLeft 内容区域 ...

  5. react-dnd使用介绍

    核心API 想要灵活使用,就先知道几个核心API DragSource 用于包装你需要拖动的组件,使组件能够被拖拽(make it draggable) DropTarget 用于包装接收拖拽元素的组 ...

  6. Connection Timeout和Command Timeout

    每次对数据库连接时,我们有时候会碰到连接超时或者命令超时,这两个超时是不一样的.以ADO.NET为例,当客户端和服务器端连接时,碰到的超时情况主要有下面几种: 当从连接池获取一个连接时,碰到超时. 当 ...

  7. 【C/C++】10分钟教你用C++写一个贪吃蛇附带AI功能(附源代码详解和下载)

    C++编写贪吃蛇小游戏快速入门 刚学完C++.一时兴起,就花几天时间手动做了个贪吃蛇,后来觉得不过瘾,于是又加入了AI功能.希望大家Enjoy It. 效果图示 AI模式演示 imageimage 整 ...

  8. NOIP模拟题汇总(加厚版)

    \(NOIP\)模拟题汇总(加厚版) T1 string 描述 有一个仅由 '0' 和 '1' 组成的字符串 \(A\),可以对其执行下列两个操作: 删除 \(A\)中的第一个字符: 若 \(A\)中 ...

  9. JAVA中 this关键字的用法

    this 在类中就是代表当前对象,可以通过 this 关键字完成当前对象的成员属性.成员方法和构造方法的调用. 那么何时用 this? 当在定义类中的方法时,如果需要调用该类对象,就可以用 this来 ...

  10. 用servlet校验密码

    一.结果图 package Login; import java.io.IOException; import java.io.PrintWriter; import java.sql.Connect ...