- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我怎样才能将 DateTime.Now
实际转换为 xsd:datetime
格式 2004-04-12T13:20:00-05:00
最后将其分配给架构 XSD 中 xsd:datetime
类型的 DateTime
属性(不是 string
)?
属性:
public System.DateTime Timestamp {
get {
return this.timestampField;
}
set {
this.timestampField = value;
}
XSD:
<!-- Timestamp Type - Timezone portion is required and fractional seconds are prohibited -->
<xsd:simpleType name="TimestampType">
<xsd:annotation>
<xsd:documentation>Base type for a date and time stamp</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="xsd:dateTime">
<xsd:pattern value="[1-9][0-9]{3}\-.+T[^\.]+(Z|[\+\-].+)"/>
</xsd:restriction>
</xsd:simpleType>
尝试以下:
Timestamp = Datetime.Now;
Timestamp = DateTime.ParseExact(DateTime.Now.ToString("O"), "O", CultureInfo.InvariantCulture);
我在根据 xsd 模式验证无效的 xml 中得到关注
<Timestamp>2014-07-18T17:27:04.3185791-04:00</Timestamp>
我正在尝试找出如何为根据 xsd 模式有效的 Timestamp 属性分配适当的值。即,2004-04-12T13:20:00-05:00 没有小数秒。
最佳答案
如果你看这个MSDN article你发现它说(强调我的):
Internally, DateTime values are represented as the number of ticks (the number of 100-nanosecond intervals) that have elapsed since 12:00:00 midnight, January 1, 0001. The actual DateTime value is independent of the way in which that value appears when displayed in a user interface element or when written to a file. The appearance of a DateTime value is the result of a formatting operation. Formatting is the process of converting a value to its string representation.
Because the appearance of date and time values is dependent on such factors as culture, international standards, application requirements, and personal preference, the DateTime structure offers a great deal of flexibility in formatting date and time values through the overloads of its ToString method. The default DateTime.ToString() method returns the string representation of a date and time value using the current culture's short date and long time pattern. The following example uses the default DateTime.ToString() method to display the date and time using the short date and long time pattern for the en-US culture, the current culture on the computer on which the example was run.
因此,基于此,您可能想尝试从您从 DateTime.Now
创建的 TimeStamp 的特定字段创建一个新的 DateTime
对象,这将清零表示时间间隔小于一秒的滴答声。如果这不起作用,您可能使用了错误的类型,请改用字符串。
即
Timestamp = Datetime.Now;
Timestamp = new DateTime(Timestamp.Year,Timestamp.Month,Timestamp.Day,Timestamp.Hour,Timestamp.Minute,Timestamp.Second,Timestamp.Kind);
关于c# - DateTime.Now 没有小数秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24835700/
我正在尝试使用以下方法对 datetime.datetime 对象列表求和: from datetime import datetime, timedelta d= [datetime.datetim
我正在尝试这个 (datetime.datetime.today()-datetime.datetime.today()).days 给出 -1 并期待值 0 而不是我得到 -1。在这种情况下,我将结
如果我列一个时间增量的列表,平均值比我对这些增量的微秒值求平均时要大。为什么会这样呢?。赠送。这是Linux上的Python3.8.10。
考虑以下片段: import datetime print(datetime.datetime.now() - datetime.datetime.now()) 在 x86_64 Linux 下的 P
如何在 SQLAlchemy 查询中比较 DateTime 字段和 datetime.datetime 对象? 例如,如果我这样做 candidates = session.query(User).f
我收到以下错误: type object 'datetime.datetime' has no attribute 'datetime' 在下面一行: date = datetime.datetime
尝试找出如何将当前日期锁定为变量,以从输入的 self.birthday 中减去。我已经查看了各种示例和链接,但无济于事......建议? from datetime import datetime
您好,我有一些 datetime.datetime 格式的日期,我用它们来过滤带有 Pandas 时间戳的 Pandas 数据框。我刚刚尝试了以下方法并获得了 2 小时的偏移量: from datet
如果您调用 datetime.datetime.now(datetime.timezone.utc) 您会得到类似 datetime.datetime(2021, 9, 8, 1, 33, 19, 6
我正在使用 pywin32 读取/写入 Excel 文件。我在 Excel 中有一些日期,以 yyyy-mm-dd hh:mm:ss 格式存储。我想将它们作为 datetime.datetime 对象
据我所知,自 Unix 纪元(1970-01-01 00:00:00 UTC)以来的秒数在全局各地应该是相同的,因为它固定为 UTC。 现在,如果您所在的时区有几个小时 +/- UTC,为什么这样做会
我正在尝试添加 datetime.datetime 和 datetime.time 以获得一列。我正在尝试结合: import datetime as dt dt.datetime.combine(m
我有一个脚本需要在脚本的不同行执行以下操作: today_date = datetime.date.today() date_time = datetime.strp(date_time_string
我在 AppEngine 上收到 type object 'datetime.datetime' has no attribute 'datetime' 错误,提示日期时间类型,但我的导入是 impo
所以我一直在使用 python 语言制作东西。我遇到了一些不太容易理解的错误: TypeError: 'datetime.datetime' object is not subscriptable (
当我运行时 from datetime import date, time, timedelta date(2012, 11, 1) + timedelta(0, 3600) 结果是 datetime
我的目标是转换 utc进入loc : use chrono::{Local, UTC, TimeZone}; let utc = chrono::UTC::now(); let loc = chron
假设您有一个 datetime.date 对象,例如 datetime.date.today() 返回的对象。 稍后您还会得到一个表示时间的字符串,它补充了日期对象。 在 datetime.datet
我试过了 In [16]: import datetime In [17]: now = datetime.datetime.utcnow() In [18]: isinstance(now, dat
我有以下代码并且收到上述错误。由于我是 python 新手,因此无法理解此处的语法以及如何修复错误: if not start or date < start: start = date 最佳答案 有
我是一名优秀的程序员,十分优秀!