472,330 Members | 1,328 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,330 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 12613
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...
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...
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...
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...
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...
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...
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...
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...
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...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.