datetime到我的json邮件主题c#

时间:2017-10-23 08:57:17

标签: c# json parsing datetime

这是我的DateTime功能。它告诉你上个月。我可以将它放入我的邮件正文中,但我也需要将它放在我的主题中。不知道该怎么做。我认为这与解析有关,但我不确定。

我的C#:

fun3

我的JSON:

{
    var currentDate = DateTime.Now;
    DateTime Uitgangstijd = BeginOfMonth(currentDate);
    DateTime Ingangstijd = Uitgangstijd.AddMonths(-1);

    var totDatum = Uitgangstijd;
    var retrieveDate = Ingangstijd;
    var dataItems = GetFromDatabase(retrieveDate, totDatum);
    var usageReport = new Core.Database.Report()
    {
        DatumVan = retrieveDate,
        DatumTot = totDatum,
        UsageItems = dataItems,
    };
    SetInDatabase(Report);
    Send(JobCancellationToken.Null, Report);

    DateTime t = BeginOfMonth(Ingangstijd);
}

private DateTime BeginOfMonth(DateTime t)
{
   return new DateTime(t.Year, t.Month, 1);
}

填充我的Json:

"Details": {
    "MailConfig": {
    "Addresses": {
      "From": "info@xxx.com",
      "To": [ "xxx@xxx.com" ],
      "CC": [],
      "BCC": []
    },
      "Subject": "Statistics_(DateTime function here)_2017"
    },
      "MailBaseUrl": "http://localhost/WebApp"
    }
}

1 个答案:

答案 0 :(得分:1)

如果您的问题是填写主题,请填写C#代码,如下所示:

你的课程:

public class DetailSettings
{
    public MailConfig MailConfig { get; set; }
    public string MailBaseUrl { get; set; }

    public DetailSettings()
    {
        MailConfig = new MailConfig();
    }
}

public class MailConfig
{
    public Addresses Addresses { get; set; }

    public string Subject { get; set; }
}

然后创建实例并填充它然后使用序列化:

DetailSettings detailsSettings = new DetailSettings();
DateTime t = BeginOfMonth(DateTime.Now);
detailsSettings.MailConfig.Subject =string.Format("Statistics_{0}_{1}", t,t.Year);
string json = new JavaScriptSerializer().Serialize(detailsSettings);