【发布时间】:2016-12-13 12:17:47
【问题描述】:
我有以下价值观:
1465509600000
1402437600000
我尝试了以下方法:
尝试1:
public long? CommitmentStartDate { get; set; }
public long? CommitmentEndDate { get; set; }
public DateTime? CommitmentStartDateDate => new DateTime( (CommitmentStartDate != null ? (long)CommitmentStartDate: Convert.ToInt64(DateTime.MinValue)) );
public DateTime? CommitmentEndDateDate => new DateTime(CommitmentEndDate != null ? (long)CommitmentEndDate: Convert.ToInt64(DateTime.MinValue));
这给了我磨损格式的日期,我明白了:
0001-01-02 16:42:30
0001-01-02 14:57:23
尝试2:
static readonly DateTime _unixEpoch =
new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
public static DateTime DateFromTimestamp(long timestamp)
{
return _unixEpoch.AddSeconds(timestamp);
}
public long? CommitmentStartDate { get; set; }
public long? CommitmentEndDate { get; set; }
public DateTime? CommitmentStartDateDate => DateFromTimestamp(CommitmentStartDate != null ? (long)CommitmentStartDate: Convert.ToInt64(DateTime.MinValue));
public DateTime? CommitmentEndDateDate => DateFromTimestamp(CommitmentEndDate != null ? (long)CommitmentEndDate: Convert.ToInt64(DateTime.MinValue));
这给了我一个 argumentOutOfRange 异常。
我该怎么做?
编辑:
预期值:
2014-06-11
2016-06-10
编辑 2:
来自日期的刻度
1402437600000 ----> 2014-06-11
1465509600000 ----> 2016-06-10
【问题讨论】:
-
绒毛太多了。请仅发布 1 个或更多示例及其预期日期值。
-
@François Wahl 这就是我在尝试转换它时使用的线程,如果您在投票关闭之前用代码通读整个问题会很好
-
DateTimes 没有与之关联的特定格式。 -
你能具体说明“刻度”代表什么吗?