C# 如何将最后7天(周末除外)写入
除了周末,我如何在最后7天写作C# 如何将最后7天(周末除外)写入,c#,C#,除了周末,我如何在最后7天写作 for (var i = -7;i == 0 ;i++) { DateTime date = new DateTime(); var Days = date.AddDays(i).ToString(); } 对于这个代码,我如何度过周末,这个代码来自今天的第7天,我需要的正好相反 如果可能的话,风险值日应为['25.05.2015'、'22.05.2015'、'21.05.2015'、'20.05.2015'、'19.05.2015'
for (var i = -7;i == 0 ;i++)
{ DateTime date = new DateTime();
var Days = date.AddDays(i).ToString();
}
对于这个代码,我如何度过周末,这个代码来自今天的第7天,我需要的正好相反
如果可能的话,风险值日应为['25.05.2015'、'22.05.2015'、'21.05.2015'、'20.05.2015'、'19.05.2015'、'18.05.2015'、'15.05.2015']
我将用这张桌子作记录
function drawVisitorsChart() {
var data = new google.visualization.DataTable();
var raw_data = [['Book', 50, 73, 104, 129, 146, 176, 139],
['Periodical', 82, 77, 98, 94, 105, 81, 104],
['Map', 50, 39, 39, 41, 47, 49, 150]];
var Days= ['x', 'x', 'x', 'x', 'x', 'x', 'x'];
data.addColumn('string', 'Month');
for (var i = 0; i < raw_data.length; ++i) {
data.addColumn('number', raw_data[i][0]);
}
data.addRows(Days.length);
for (var j = 0; j < Days.length; ++j) {
data.setValue(j, 0, months[j]);
}
for (var i = 0; i < raw_data.length; ++i) {
for (var j = 1; j < raw_data[i].length; ++j) {
data.setValue(j - 1, i + 1, raw_data[i][j]);
}
}
var div = $('#daily_div');
new google.visualization.ColumnChart(div.get(0)).draw(data, {
title: 'Daily Record',
width: div.width(),
height: 330,
legend: 'right',
yAxis: { title: '(thousands)' }
});
函数drawVisitorsChart(){
var data=new google.visualization.DataTable();
var raw_数据=[[Book',50,73,104,129,146,176,139],
[‘定期’、82、77、98、94、105、81、104],
[‘地图’、50、39、39、41、47、49、150];
变量天数=['x','x','x','x','x','x','x','x'];
data.addColumn('string','Month');
对于(变量i=0;i
使用AddBusinessDays
:
for (var i = -7;i == 0 ;i++)
{
DateTime date = new DateTime();
var Days = date.AddBusinessDays(i).ToString();
}
与:
公共静态类DateTimeExtensions
{
公共静态日期时间AddBusinessDays(此日期时间日期,整数天)
{
双符号=Convert.ToDouble(数学符号(天));
int unsignedDays=数学符号(天)*天;
对于(int i=0;i
阅读更多
编辑:重复的。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SkipWeekends
{
class Program
{
static List<DateTime> GetBusinessDays(DateTime startDate, int numDays)
{
var dates = new List<DateTime>();
var step = (numDays < 0) ? -1 : 1;
var date = startDate;
var absNumDays = Math.Abs(numDays);
while(dates.Count() < absNumDays)
{
date = date.AddDays(step);
if (date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday)
continue;
dates.Add(date);
}
return dates;
}
static void Main(string[] args)
{
var dates = new List<DateTime>();
var start = DateTime.Now;
dates = GetBusinessDays(start, 14);
Console.WriteLine("14 Business Days in the Future:\n");
foreach(var date in dates)
{
Console.WriteLine(date.ToString());
}
dates = GetBusinessDays(start, -14);
Console.WriteLine("\n\n14 Business Days in the Past:\n");
foreach (var date in dates)
{
Console.WriteLine(date.ToString());
}
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
命名空间SkipWeekends
{
班级计划
{
静态列表GetBusinessDays(日期时间开始日期,整数天)
{
变量日期=新列表();
var步长=(numDays<0)?-1:1;
var日期=起始日期;
var absNumDays=Math.Abs(numDays);
while(dates.Count()
json函数中的某些json数据和解析中的linq问题在哪里?请修改您的问题并澄清您的问题
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SkipWeekends
{
class Program
{
static List<DateTime> GetBusinessDays(DateTime startDate, int numDays)
{
var dates = new List<DateTime>();
var step = (numDays < 0) ? -1 : 1;
var date = startDate;
var absNumDays = Math.Abs(numDays);
while(dates.Count() < absNumDays)
{
date = date.AddDays(step);
if (date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday)
continue;
dates.Add(date);
}
return dates;
}
static void Main(string[] args)
{
var dates = new List<DateTime>();
var start = DateTime.Now;
dates = GetBusinessDays(start, 14);
Console.WriteLine("14 Business Days in the Future:\n");
foreach(var date in dates)
{
Console.WriteLine(date.ToString());
}
dates = GetBusinessDays(start, -14);
Console.WriteLine("\n\n14 Business Days in the Past:\n");
foreach (var date in dates)
{
Console.WriteLine(date.ToString());
}
}
}
}