|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
FAST date string conversion ?A quick question,
I have a string with a date in european format, e.g. "30/4/2006". What is the FASTEST way to produce the corresponding string in USA format "4/30/2006" and asian format "2006/4/30" ? -pam Pam,
Define "fastest", I would be more concerned with the "proper" way of doing it. If I had a date in d/m/y format & wanted m/d/y or y/m/d formats I would simply use DateTime.Parse & DateTime.ToString. As Parse & ToString are the "proper" ways of doing (who better then the type itself to have convert to & from various formats). Something like: Const dmy As String = "d/M/yyyy" Const mdy As String = "M/d/yyyy" Const ymd As String = "yyyy/M/d" Dim european As String = "30/4/2006" Dim someDate As Date = DateTime.ParseExact(european, dmy, Nothing) Dim usa As String = someDate.ToString(mdy) Dim asian As String = someDate.ToString(ymd) NOTE: Convert.ToString & Convert.ToDateTime ultimately call DateTime.Parse & DateTime.ToString... -- Show quoteHide quoteHope this helps Jay B. Harlow [MVP - Outlook] ..NET Application Architect, Enthusiast, & Evangelist T.S. Bradley - http://www.tsbradley.net <pamelaflue***@libero.it> wrote in message news:1148567185.670632.305690@u72g2000cwu.googlegroups.com... |A quick question, | | I have a string with a date in european format, e.g. "30/4/2006". | | What is the FASTEST way to produce the corresponding string in USA | format | "4/30/2006" and asian format "2006/4/30" ? | | -pam | Thank you Jay, it helps a lot !
I have a doubt, why for the year there are 4 yyyy and for day/month on one (intuitively one would expect 2 chars ). Thanks again, -pam PS by "fast" I meant the most efficient way in terms of speed of execution. Probably the one you suggest :-) I used one on day & month so as to allow the 1st thru the 9th. without
requiring a leading zero. It allows "30/4/2006" rather then require "30/04/2006" -- Show quoteHide quoteHope this helps Jay B. Harlow [MVP - Outlook] ..NET Application Architect, Enthusiast, & Evangelist T.S. Bradley - http://www.tsbradley.net <pamelaflue***@libero.it> wrote in message news:1148573460.120392.182790@y43g2000cwc.googlegroups.com... | Thank you Jay, it helps a lot ! | | I have a doubt, why for the year there are 4 yyyy and for day/month on | one | (intuitively one would expect 2 chars ). | | Thanks again, | | -pam | | PS by "fast" I meant the most efficient way in terms of speed of | execution. Probably the one you suggest :-) | Very good. Thank you very much!
I guess that with the same logic it could be safe to use only 2 chars for the year (yy) ... -pam Jay,
Just for you as American, > It allows "30/4/2006" rather then require "30/04/2006" The second is AFAIK more common in Europe, that as well for the days.Cor Show quoteHide quote > > > -- > Hope this helps > Jay B. Harlow [MVP - Outlook] > .NET Application Architect, Enthusiast, & Evangelist > T.S. Bradley - http://www.tsbradley.net > > > <pamelaflue***@libero.it> wrote in message > news:1148573460.120392.182790@y43g2000cwc.googlegroups.com... > | Thank you Jay, it helps a lot ! > | > | I have a doubt, why for the year there are 4 yyyy and for day/month on > | one > | (intuitively one would expect 2 chars ). > | > | Thanks again, > | > | -pam > | > | PS by "fast" I meant the most efficient way in terms of speed of > | execution. Probably the one you suggest :-) > | > >
Problem loading XML
playing & re-playing 7 .wav files How To Force Copy One File To Another datagrid current record Debug.WriteLine Doesn't Produce Output Possible to monitor changes in array (with event)? Problems with URL Syntax Re: How to Use a Screen Saver app within My Application? How do I add a MSI file to Prerequisite list? Stripping just the filename |
|||||||||||||||||||||||