I have read through various posts on converting a string into the datetime format, but cannot resolve my situation. I have a string in the format of 'yyyymmddthhmmss.sssz' that I would like to convert to datetime. My previous attempts:
DateTime dt = DateTime.Parse(string);
DateTime dt = Convert.ToDateTime(string);
DateTime dt = XmlConvert.ToDateTime(string, format); where format = 'yyyymmddthhmmss.sssz'
I should note that the string value is being extracted from an Xml document. Any help would be appreciated.
9 10827
I have read through various posts on converting a string into the datetime format, but cannot resolve my situation. I have a string in the format of 'yyyymmddthhmmss.sssz' that I would like to convert to datetime. My previous attempts:
DateTime dt = DateTime.Parse(string);
DateTime dt = Convert.ToDateTime(string);
DateTime dt = XmlConvert.ToDateTime(string, format); where format = 'yyyymmddthhmmss.sssz'
I should note that the string value is being extracted from an Xml document. Any help would be appreciated.
Just a quick thought, are you removing the surround tag elements from your string before you try to parse it?
Just a quick thought, are you removing the surround tag elements from your string before you try to parse it?
I am using XmlResolver.CreateNavigator to extract string values out via the xpath, so only the contents of the given tag are being extracted, not the tag in its entirety.
Plater 7,872
Recognized Expert Expert
I would recomend DateTime.ParseExact() (Normally I would say .Parse() or .TryParse() but it didn't look like they supported custom formats like that) -
// "20080129P015750.100-5" <-you cannot get better format then that?
-
string format="yyyyMMddthhmmss.sssz";
-
//NOTE: I had to fix your format, as you had "2 digit minutes" specified in there twice
-
DateTime dt = DateTime.ParseExact(string, format, <some format provider>);
-
Have to check in on what format provider you wanna use, msdn should help.
// "20080129P015750.100-5" <-you cannot get better format then that?
Unfortunately this is someone's idea of a "standard".
Plater 7,872
Recognized Expert Expert
Did correcting the format string have any effect?
You could always write your own too if need be.
Did correcting the format string have any effect?
You could always write your own too if need be.
It kept saying that the string was not a valid date format. I broke down and removed the extra characters so that it was simply 'yyyyMMddHHmmss'. Below did not work for me.
string = "20071026T120000.000Z";
IFormatProvider US_Format = new System.Globalization.CultureInfo("en-US", true);
string format = "yyyyMMddTHHmmss".sssZ;
RefDateTimeStamp = DateTime.ParseExact(string, format, US_Format);
Plater 7,872
Recognized Expert Expert
Oh the Z was a literal and not the designation for gmt offset? The same with the T, it is not the AM/PM designator but ACTUALLY a T?
What is an example of the exact string you will be parsing?
EDIT: ok I found more problems with your date format string, and have corrected with the following example: -
string s = "20071026A120000.000-5";//example string to parse
-
IFormatProvider US_Format = new System.Globalization.CultureInfo("en-US", true);
-
string format = "yyyyMMddtHHmmss.fffz";
-
DateTime dt = DateTime.ParseExact(s, format, US_Format);
-
MessageBox.Show(dt.ToString());
-
Try this
DateTime.Now.ToString("yyyymmddthhmmss.fff tt")
tt for AM/PM
string = "20071026T120000.000Z";
In the above string what is 'T' stands for?
If nothing works try the below
Dim s As String = "20071026T120000.000Z" //Assuming T stands for time
s = s.Insert(4, "/")
s = s.Insert(7, "/")
s = s.Replace("T", " ")
s = s.Replace("Z", "")
s = s.Insert(13, ":")
s = s.Insert(16, ":")
MessageBox.Show(Convert.ToDateTime(s))
Is it helpful?
It kept saying that the string was not a valid date format. I broke down and removed the extra characters so that it was simply 'yyyyMMddHHmmss'. Below did not work for me.
string = "20071026T120000.000Z";
IFormatProvider US_Format = new System.Globalization.CultureInfo("en-US", true);
string format = "yyyyMMddTHHmmss".sssZ;
RefDateTimeStamp = DateTime.ParseExact(string, format, US_Format);
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Nathan |
last post by:
Is there a way to convert a string to a CipherMessage? I am calling a
function that decrypts a CipherMessage and returns the value. The only
problem is when I want to use an encrypted value stored...
|
by: Vicki Carlsen |
last post by:
Hi,
What is the easiest way to convert a DateTime object to a
long?? - And the other way back??
(For database use)
Regards,
Vicki
|
by: ad |
last post by:
I use a textbox for user to enter a date.
How can I determine if the string can convert to datetime.
|
by: Petr Jakes |
last post by:
Hi,
I am trying to convert string to the "escaped string".
example: from "0xf" I need "\0xf"
I am able to do it like:
a="0xf"
escaped_a=("\%s" % a ).decode("string_escape")
But it looks a...
|
by: Fabio |
last post by:
Hi all!
A simple question: I need to convert a DateTime var to a byte (or to a
Int64).
How?
Thanks!
--
| |
by: Ursula |
last post by:
Is it possible to convert a string in a file. The problem is this:
I have an object string that is a file xml and I want to pass to Deserialize
function, but Deserialize function expect an object...
|
by: Peter |
last post by:
Trying to convert string to byte array.
the following code returns byte array of {107, 62, 194, 139, 64}
how can I convert this string to a byte array of {107, 62, 139, 65}
...
|
by: engteng |
last post by:
How do I convert string to numeric in VB.NET 2003 ?
Example convert P50001 to 50001 or 50001P to 50001 but if P is in middle
then not convert.
Regards,
Tee
|
by: tanishka singh |
last post by:
How do you convert string from database into date in asp.net?
Dim output = (From tlb In obj.SelectRecordAll_SalesInquiryRegister _
Join tlb1 In LatestPOs On tlb.SIR_OfferNo...
|
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,...
|
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,...
| |
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...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |