Convert UTC DateTime to DateTimeOffset

I need to convert UTC date strings to DateTimeOffsets . This must work with a timezone which differs from the computers timezone. Eg current computer timezone is +02:00, but I want to create a DateTimeOffset with offset -4:00. I already read lot of questions here on stackoverflow, but none of them solved my problem. That is what I need to do: Input: "2012-11-20T00:00:00Z" Out

将UTC日期时间转换为DateTimeOffset

我需要将UTC日期字符串转换为DateTimeOffsets 。 这必须使用与计算机时区不同的时区。 例如当前的计算机时区为+02:00,但我想创建一个偏移量为-4:00的DateTimeOffset。 我已经在这里阅读了很多关于stackoverflow的问题,但是他们都没有解决我的问题。 这就是我需要做的事情: 输入: “2012-11-20T00:00:00Z” 输出: DateTimeOffset与: UtcDateTime of 2012-11-20 00:00 定义的时区的正确Utc偏移量(本例中为

Creating a DateTime in a specific Time Zone in c#

I'm trying to create a unit test to test the case for when the timezone changes on a machine because it has been incorrectly set and then corrected. In the test I need to be able to create DateTime objects in a none local time zone to ensure that people running the test can do so successfully irrespective of where they are located. From what I can see from the DateTime constructor I can s

在c#中的特定时区中创建日期时间

我试图创建一个单元测试来测试机器上时区更改的情况,因为它已被错误地设置并更正。 在测试中,我需要能够在非本地时区创建DateTime对象,以确保运行测试的人员可以成功完成任务,而不管它们位于何处。 从我可以从DateTime构造函数中看到,我可以将TimeZone设置为本地时区,UTC时区或未指定。 如何创建一个像PST一样的特定时区的DateTime? Jon的回答是关于TimeZone的,但我建议使用TimeZoneInfo。 就我个人而言,我喜

Serialize an object to XML

I have a C# class that I have inherited. I have successfully "built" the object. But I need to serialize the object to XML. Is there an easy way to do it? It looks like the class has been set up for serialization, but I'm not sure how to get the XML representation. My class definition looks like this: [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")] [Sys

将对象序列化为XML

我有一个我继承的C#类。 我已经成功“构建”了这个对象。 但我需要将对象序列化为XML。 有没有简单的方法来做到这一点? 看起来类已经设置为序列化,但我不知道如何获得XML表示。 我的类定义如下所示: [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute(

C# DateTime to "YYYYMMDDHHMMSS" format

I want to convert a C# DateTime to "YYYYMMDDHHMMSS" format. But I don't find a built in method to get this format? Any comments? DateTime.Now.ToString("yyyyMMddHHmmss"); // case sensitive This site has great examples check it out // create date time 2008-03-09 16:05:07.123 DateTime dt = new DateTime(2008, 3, 9, 16, 5, 7, 123); String.Format("{0:y yy yyy yyyy}", dt); // "8

C#日期时间为“YYYYMMDDHHMMSS”格式

我想将C#日期时间转换为“YYYYMMDDHHMMSS”格式。 但我没有找到一种内置的方法来获得这种格式? 任何意见? DateTime.Now.ToString("yyyyMMddHHmmss"); // case sensitive 这个网站有很好的例子检查出来 // create date time 2008-03-09 16:05:07.123 DateTime dt = new DateTime(2008, 3, 9, 16, 5, 7, 123); String.Format("{0:y yy yyy yyyy}", dt); // "8 08 008 2008" year String.Format("{0:M MM MMM MMMM}",

Override DateTime serialization to string

In my WPF app, I want to give the user the option to present all the dates in different time zones. That is, to keep the data as is but only present it differently in TextBlock Text Binding to DateTime . I'm trying to achieve this without introducing a wrapping type or else use converters - this would be bad design as this could easily be missed by other developers who would be working on

将DateTime序列化重写为字符串

在我的WPF应用程序中,我想给用户提供在不同时区显示所有日期的选项。 也就是说,要保持数据原样,但仅在TextBlock Text Binding to DateTime中以不同方式呈现。 我试图在不引入包装类型或使用转换器的情况下实现此目的 - 这将是糟糕的设计,因为其他开发人员很容易就会忽略这些代码。 此外,现有的代码可以保持不变。 有没有办法在DateTime序列化中干预TextBlock绑定内部的字符串,并在那里插入我自己的逻辑? 使用自定

Convert dateTime to ISO format yyyy

This question already has an answer here: Given a DateTime object, how do I get an ISO 8601 date in string format? 13 answers There is no standard format for the readable 8601 format. You can use a custom format: theDate.ToString("yyyy-MM-dd HH':'mm':'ss") (The standard format "s" will give you a "T" between the date and the time, not a space.) To use the strict ISO8

将dateTime转换为ISO格式yyyy

这个问题在这里已经有了答案: 给定一个DateTime对象,如何获得字符串格式的ISO 8601日期? 13个答案 可读的8601格式没有标准格式。 您可以使用自定义格式: theDate.ToString("yyyy-MM-dd HH':'mm':'ss") (标准格式“s”会在日期和时间之间给出“T”,而不是空格。) 要使用严格的ISO8601 ,您可以使用s (可排序)格式字符串: myDate.ToString("s"); // example 2009-06-15T13:45:30 这是这个自定义格式字符串的一

ASP.NET MVC URL generation performance

A little benchmark with ASP.NET MVC. Viewpage code: public string Bechmark(Func<string> url) { var s = new Stopwatch(); var n = 1000; s.Reset(); s.Start(); for (int i = 0; i < n; i++) { var u = url(); } s.Stop(); return s.ElapsedMilliseconds + " ms, " + ((s.ElapsedMilliseconds) / (float)n) + "

ASP.NET MVC URL生成性能

与ASP.NET MVC的一点基准。 浏览页面代码: public string Bechmark(Func<string> url) { var s = new Stopwatch(); var n = 1000; s.Reset(); s.Start(); for (int i = 0; i < n; i++) { var u = url(); } s.Stop(); return s.ElapsedMilliseconds + " ms, " + ((s.ElapsedMilliseconds) / (float)n) + " ms per link

Ajax file upload in mvc application

in my MVC app i using Ajax upload (Version 3.5 (23.06.2009)) in this part of code: <div id="userPhotosUpload"> <span class="tabs_fieldDesc">@Html.Label("txtPhotoDescription", "Desc")</span> @Html.TextBox("txtPhotoDescription", "", new { @maxlength = "30", @class = "tabs_fullLength" }) <div class="buttonLine"> <button id="btnAddUserPhoto"

在mvc应用程序中上传Ajax文件

在我的MVC应用程序中,我使用Ajax上传(版本3.5(23.06.2009))在这部分代码中: <div id="userPhotosUpload"> <span class="tabs_fieldDesc">@Html.Label("txtPhotoDescription", "Desc")</span> @Html.TextBox("txtPhotoDescription", "", new { @maxlength = "30", @class = "tabs_fullLength" }) <div class="buttonLine"> <button id="btnAddUserPhoto">Ad

Get Json string of Model, with all changes made by user

This question already has an answer here: Convert form data to JavaScript object with jQuery 50 answers You cannot manipulate your c# model from JavaScript.Your model rendered by the server. Only once. When your page is created. To send data from your form or etc. use JSON.stringify(object)

获取Model的Json字符串,以及用户所做的所有更改

这个问题在这里已经有了答案: 使用jQuery将表单数据转换为JavaScript对象50个答案 您无法使用JavaScript处理您的c#模型。您的模型由服务器呈现。 只有一次。 当你的页面被创建。 要从表单等发送数据,请使用JSON.stringify(object)

How to change the HTTP Request Content Type for FLURL Client?

I am using flurl to submit HTTP request and this is very useful. Now I need to change the " Content-Type" header for some of the requests to "application/json;odata=verbose" public async Task<Job> AddJob() { var flurlClient = GetBaseUrlForGetOperations("Jobs").WithHeader("Content-Type", "application/json;odata=verbose"); return await flurlClien

如何更改FLURL客户端的HTTP请求内容类型?

我使用flurl来提交HTTP请求,这非常有用。 现在我需要为“application / json; odata = verbose”的某些请求更改“ Content-Type”标头 public async Task<Job> AddJob() { var flurlClient = GetBaseUrlForGetOperations("Jobs").WithHeader("Content-Type", "application/json;odata=verbose"); return await flurlClient.PostJsonAsync(new { //Some parameters here which