473,769 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parsing a UTC string from a weblog into a DateTime

I am trying to create a web service that takes a string from my web server
in the following format:

Mon, 6 Oct 2003 18:39:47 UTC

and put's in a datetime so it can then be reformatted in C# as necessary
for variuos purposes.

There is something wrong with the following code. I get the following error
when I enter in the above date string:

System.FormatEx ception: String was not recognized as a valid DateTime.
at System.DateTime Parse.ParseForm atError(Boolean isThrowExceptio n, String
resourceID)
at System.DateTime Parse.DoStrictP arse(String s, String formatParam,
DateTimeStyles styles, DateTimeFormatI nfo dtfi, Boolean isThrowExp,
DateTime& returnValue)
at System.DateTime Parse.ParseExac t(String s, String format,
DateTimeFormatI nfo dtfi, DateTimeStyles style)
at System.DateTime .ParseExact(Str ing s, String format, IFormatProvider
provider)
at DateTest.Servic e1.TestDate(Str ing inputDate) in
\\commerce.lede t.com\wwwroot$\ datetest\servic e1.asmx.cs:line 69
Can anyone tell me what's wrong with the code below??

[WebMethod]

public string TestDate(string inputDate)

{

// Define a custom string format to display the DateTime value.

// zzzz specifies the full time zone offset.

String expectedFormat = "ddd, d MMM yyyy hh:mm:ss";

System.DateTime ouputDateTime =

System.DateTime .ParseExact(inp utDate, expectedFormat, null);

return ouputDateTime.T oString();

}
Nov 15 '05 #1
2 12725
There is no direct way to do the conversion.

It's the "UTC" in the string causing the problem.

Will this work for you?

public string TestDate(string inputDate)
{
// Define a custom string format to display the DateTime value.
// zzzz specifies the full time zone offset.

string myDate = inputDate.Repla ce("UTC", string.Empty);
System.DateTime ouputDateTime
= System.DateTime .Parse(myDate);

return ouputDateTime.T oString();
}

Hope this helps.
Brian W
"Sterling Ledet" <sj*****@ledet. com> wrote in message
news:e$******** ******@TK2MSFTN GP12.phx.gbl...
I am trying to create a web service that takes a string from my web server
in the following format:

Mon, 6 Oct 2003 18:39:47 UTC

and put's in a datetime so it can then be reformatted in C# as necessary
for variuos purposes.

There is something wrong with the following code. I get the following error when I enter in the above date string:

System.FormatEx ception: String was not recognized as a valid DateTime.
at System.DateTime Parse.ParseForm atError(Boolean isThrowExceptio n, String resourceID)
at System.DateTime Parse.DoStrictP arse(String s, String formatParam,
DateTimeStyles styles, DateTimeFormatI nfo dtfi, Boolean isThrowExp,
DateTime& returnValue)
at System.DateTime Parse.ParseExac t(String s, String format,
DateTimeFormatI nfo dtfi, DateTimeStyles style)
at System.DateTime .ParseExact(Str ing s, String format, IFormatProvider
provider)
at DateTest.Servic e1.TestDate(Str ing inputDate) in
\\commerce.lede t.com\wwwroot$\ datetest\servic e1.asmx.cs:line 69
Can anyone tell me what's wrong with the code below??

[WebMethod]

public string TestDate(string inputDate)

{

// Define a custom string format to display the DateTime value.

// zzzz specifies the full time zone offset.

String expectedFormat = "ddd, d MMM yyyy hh:mm:ss";

System.DateTime ouputDateTime =

System.DateTime .ParseExact(inp utDate, expectedFormat, null);

return ouputDateTime.T oString();

}

Nov 15 '05 #2
Add UTC on the format specs:
"ddd, d MMM yyyy hh:mm:ss UTC"

Cheers!
--
/jop
"Sterling Ledet" <sj*****@ledet. com> wrote in message
news:e$******** ******@TK2MSFTN GP12.phx.gbl...
I am trying to create a web service that takes a string from my web server
in the following format:

Mon, 6 Oct 2003 18:39:47 UTC

and put's in a datetime so it can then be reformatted in C# as necessary
for variuos purposes.

There is something wrong with the following code. I get the following error when I enter in the above date string:

System.FormatEx ception: String was not recognized as a valid DateTime.
at System.DateTime Parse.ParseForm atError(Boolean isThrowExceptio n, String resourceID)
at System.DateTime Parse.DoStrictP arse(String s, String formatParam,
DateTimeStyles styles, DateTimeFormatI nfo dtfi, Boolean isThrowExp,
DateTime& returnValue)
at System.DateTime Parse.ParseExac t(String s, String format,
DateTimeFormatI nfo dtfi, DateTimeStyles style)
at System.DateTime .ParseExact(Str ing s, String format, IFormatProvider
provider)
at DateTest.Servic e1.TestDate(Str ing inputDate) in
\\commerce.lede t.com\wwwroot$\ datetest\servic e1.asmx.cs:line 69
Can anyone tell me what's wrong with the code below??

[WebMethod]

public string TestDate(string inputDate)

{

// Define a custom string format to display the DateTime value.

// zzzz specifies the full time zone offset.

String expectedFormat = "ddd, d MMM yyyy hh:mm:ss";

System.DateTime ouputDateTime =

System.DateTime .ParseExact(inp utDate, expectedFormat, null);

return ouputDateTime.T oString();

}

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
9445
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $ Last-Modified: $Date: 2003/10/28 19:48:44 $ Author: A.M. Kuchling <amk@amk.ca> Status: Draft Type: Standards Track
9
2776
by: Thomas W | last post by:
I'm developing a web-application where the user sometimes has to enter dates in plain text, allthough a format may be provided to give clues. On the server side this piece of text has to be parsed into a datetime python-object. Does anybody have any pointers on this? Besides the actual parsing, my main concern is the different locale date formats and how to be able to parse those strange us-like "month/day/year" compared to the clever...
2
382
by: Simon | last post by:
Hi all If I have a method for inserting data to database and it take a parameter dateTime in String. Since C# does not have a function to test date like IsDate in VB.Net. Would it be a good idea to use a static method in a static object to convert the dateTime to DateTime datatype as follows public static DateTime ParseDate(String dateTime tr return DateTime.Parse(dateTime)
50
4957
by: z. f. | last post by:
HI, i have string in format dd/mm/yyyyy hh:mm:ss and giving this as an input to DateTime.Parse gives a string was not recognized as a valid date time format string error. how do i make the parse method to accept formating that i need. if i do console.writeLine DateTime.Now.ToString it gives the format: YYYY-MM-DD HH:MM:SS TIA, Z.
18
4881
by: Atara | last post by:
In my apllication I use the following code: '-- My Code: Public Shared Function strDate2Date(ByVal strDate As String) As System.DateTime Dim isOk As Boolean = False If (strDate Is Nothing) Then isOk = False ElseIf Not (strDate.Length() = 6) Then isOk = False
4
6421
by: Michael Meckelein | last post by:
Hello, Wondering, if C# (framework 2.0) does not support parsing DateTime timezones in three letter acronyms. I would like to parse date strings like "2005 Nov 01 11:58:47.490 CST -6:00" but it seems C# does not support the timezone letters (CST). I suppose to use the symbol ZZZ for the timezone letters, but MSDE pointed out that it is not supported in C#, isn't it?
0
1138
by: Uncle Leo | last post by:
I created an OleDbDataAdapter with the wizard in Visual Studio 2003. It created a dataset, connectionstring etc. for me to work with. It also created a .xsd file where one of the columns type is set to date. My program is being used in many different countries, and many different local settings. Some time ago a user from Turkey contacted me saying my program crashed on his system with the following error code: System.ArgumentException:...
2
1880
by: Adrian | last post by:
Hi All, Is there anyway to change what isspace thinks is a space character. I am parsing some log files and it would be nice to just read a field as what ever is between quotes or between 's ie clf log files I know I can go char by char or find_last_of etc, but I would like to know if it is possible with locales and facets? Also are there any suggestions for outputting in multiple languages? Can I use locales again? I was just...
8
5147
by: thunderbolt | last post by:
Hi, How do i parse a string "ABC 2005 (12)" and convert it to "ABC 2005 (Dec)" in C#? The number within the brackets represent month.. am new to c# and breaking head for couple of hours over this seemingly simple thing, would be glad if anybody could help. Thanks in Advance, Ajai
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10045
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5299
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3959
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.