473,226 Members | 1,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,226 software developers and data experts.

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.FormatException: String was not recognized as a valid DateTime.
at System.DateTimeParse.ParseFormatError(Boolean isThrowException, String
resourceID)
at System.DateTimeParse.DoStrictParse(String s, String formatParam,
DateTimeStyles styles, DateTimeFormatInfo dtfi, Boolean isThrowExp,
DateTime& returnValue)
at System.DateTimeParse.ParseExact(String s, String format,
DateTimeFormatInfo dtfi, DateTimeStyles style)
at System.DateTime.ParseExact(String s, String format, IFormatProvider
provider)
at DateTest.Service1.TestDate(String inputDate) in
\\commerce.ledet.com\wwwroot$\datetest\service1.as mx.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(inputDate, expectedFormat, null);

return ouputDateTime.ToString();

}
Nov 15 '05 #1
2 12676
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.Replace("UTC", string.Empty);
System.DateTime ouputDateTime
= System.DateTime.Parse(myDate);

return ouputDateTime.ToString();
}

Hope this helps.
Brian W
"Sterling Ledet" <sj*****@ledet.com> wrote in message
news:e$**************@TK2MSFTNGP12.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.FormatException: String was not recognized as a valid DateTime.
at System.DateTimeParse.ParseFormatError(Boolean isThrowException, String resourceID)
at System.DateTimeParse.DoStrictParse(String s, String formatParam,
DateTimeStyles styles, DateTimeFormatInfo dtfi, Boolean isThrowExp,
DateTime& returnValue)
at System.DateTimeParse.ParseExact(String s, String format,
DateTimeFormatInfo dtfi, DateTimeStyles style)
at System.DateTime.ParseExact(String s, String format, IFormatProvider
provider)
at DateTest.Service1.TestDate(String inputDate) in
\\commerce.ledet.com\wwwroot$\datetest\service1.as mx.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(inputDate, expectedFormat, null);

return ouputDateTime.ToString();

}

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$**************@TK2MSFTNGP12.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.FormatException: String was not recognized as a valid DateTime.
at System.DateTimeParse.ParseFormatError(Boolean isThrowException, String resourceID)
at System.DateTimeParse.DoStrictParse(String s, String formatParam,
DateTimeStyles styles, DateTimeFormatInfo dtfi, Boolean isThrowExp,
DateTime& returnValue)
at System.DateTimeParse.ParseExact(String s, String format,
DateTimeFormatInfo dtfi, DateTimeStyles style)
at System.DateTime.ParseExact(String s, String format, IFormatProvider
provider)
at DateTest.Service1.TestDate(String inputDate) in
\\commerce.ledet.com\wwwroot$\datetest\service1.as mx.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(inputDate, expectedFormat, null);

return ouputDateTime.ToString();

}

Nov 15 '05 #3

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

Similar topics

8
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 $...
9
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...
2
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...
50
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...
18
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)...
4
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...
0
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...
2
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...
8
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...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.