小编Ger*_*Ger的帖子

将负.days转换为0?

我试图将"合同"的"结束日期"与datetime.now进行比较.显然,如果今天的日期超过合约结束日期,则该值将返回为负数.我想要一个负值返回为0,而已发生的任何结束日期将返回为正值.

目前,正值正常工作,但负值返回为:

-41641

用于计算值的代码如下:

var contractEndDate = contract.EndDate;
var ts = contractEndDate.Value.Subtract(DateTime.Now);
var contractDaysRemaining = ts.Days;
Run Code Online (Sandbox Code Playgroud)

contractDaysRemaining然后在代码中返回值.

我对c#很陌生,想知道如何将负的ContractDaysRemaining转换为0,同时保持正值不变.

提前致谢!

c# datetime negative-number

3
推荐指数
1
解决办法
137
查看次数

使用Powershell创建注册表项

我试图使用PowerShell检查注册表中是否存在密钥结构.如果结构不存在,我需要创建它,然后我需要在结束文件夹中创建键.如果我单独运行代码段来创建密钥,它们就可以很好地创建.但是运行块本身(确保在注册表中手动确保密钥不存在)它将不会创建文件夹结构.不确定是什么问题.任何帮助将是欣赏.代码如下:

$Registry_Paths = "hkcu:\Software\Microsoft\Office\14.0", "hkcu:\Software\Microsoft\Office\14.0\Groove", "hkcu:\Software\Microsoft\Office\14.0\Groove\Development"

foreach($Registry_Path in $Registry_Paths)
{
$Test_Path_Result = Test-Path -Path $Registry_Path
if($Test_Path_Result -eq $false)
{
    $Registry_Key_Log += "Warning: No registry key path found at " + $Registry_Path +"`n"
    $Registry_Key_Log += "Creating key now for " + $Registry_Path + "`n" + "`n"

    if($Registry_Path -eq "hkcu:\Software\Microsoft\Office\14.0")
    {
        try{
        New-Item -Path "HKCU:\Software\Microsoft\Office\14.0" -ItemType Key
        }
        catch
        {
            $Error_Log += "Warning: There was an error when attempting to create a new registry key, or key property for $Registry_Path"
            $Error_Log += …
Run Code Online (Sandbox Code Playgroud)

registry powershell powershell-3.0

3
推荐指数
1
解决办法
2万
查看次数