tostring

search for more blogs here

 

"Using and formatting DateTime and TimeSpan data types" posted by ~Ray
Posted on 2008-11-13 12:19:34

One of the most useful constructs in the. NET Framework is the ease of use for date/time manipulation. I need to manipulate dates and time frequently either displaying them or parsing strings containing them. DateTime dt;dt = DateTime. MinValue;Console. WriteLine(dt. ToString());dt = DateTime. MaxValue;Console. WriteLine(dt. ToString());dt = DateTime. Today;Console. WriteLine(dt. ToString());dt = DateTime. Now;Console. WriteLine(dt. ToString());dt = DateTime. UtcNow;Console. WriteLine(dt. ToString()); represents today with the time component in Universal Coordinated Time. Taking the date of this post again it’ll be year 2007. November 2nd. And (for example) the time is 1st hour. 1st minute and 34th second. I’m in Singapore so the time zone offset is 8 hours ahead of UTC. is particularly useful when you deal with international data where the dates and times can span across many countries. In this case having one standard time offset makes manipulating and displaying dates and times easy. Then people won’t keep asking “Is this American time or London time or Singapore time?” Just display and let the users add or subtract their own time zone offset to obtain data in their local time. DateTime dt;// 2nd Nov 2007. 1:15 pm. 45th second. 853rd milliseconddt = new DateTime(2007. 11. 2. 13. 15. 45. 853);Console. WriteLine(dt. ToString());// get the same date by parsing a stringdt = DateTime. ParseExact("20071102131545". "yyyyMMddHHmmss" null);Console. WriteLine(dt. ToString());// get the same date by parsing a string formatted differentlydt = DateTime. ParseExact("02/11/2007 13:15:45". "dd/MM/yyyy HH:mm:ss" null);Console. WriteLine(dt. ToString()); I like to have exact control over how a date/time string is interpreted and I want any culture-specific information to be left out of the parsing. If you know exactly what you have and what you need it’s better to do it yourself rather than letting the code do implicit conversions. I’m paranoid that way… DateTime dt;dt = new DateTime(2007. 11. 2. 13. 15. 45. 853);// get 2 Nov 2007 01:15 PMConsole. WriteLine(dt. ToString("d MMM yyyy hh:mm tt"));// get November 02. 2007 13:15Console. WriteLine(dt. ToString("MMMM dd yyyy HH:mm"));// get 2007-11-02T13:15:45.8+08:00Console. WriteLine(dt. ToString("yyyy-MM-ddTHH:mm:ss fzzz")); DateTime dtStart dtEnd;int iDaysInMonth = 0;dtStart = DateTime. Now;dtStart = new DateTime(dtStart. Year dtStart. Month. 1. 0. 0. 0. 0);dtEnd = DateTime. Now;iDaysInMonth = DateTime. DaysInMonth(dtEnd. Year dtEnd. Month);dtEnd = new DateTime(dtEnd. Year dtEnd. Month iDaysInMonth. 23. 59. 59. 999);Console. WriteLine("The first day of the month is {0}" dtStart. ToString("dd/MM/yyyy HH:mm:ss"));Console. WriteLine("The last day of the month is {0}" dtEnd. ToString("dd/MM/yyyy HH:mm:ss")); function. The number of days in the specific month is also the last day of the month. No fuss no muss. This is way better than you implementing a custom function which probably involves some arcane calculation with leap and non-leap years. If you do it wrongly you’ll end up with 28 days instead of 29 for certain February’s. The DateTime dtStart dtEnd;dtStart = new DateTime(2007. 10. 27);dtEnd = new DateTime(2007. 11. 2. 13. 15. 45. 853);TimeSpan ts = dtEnd - dtStart;Console. WriteLine(ts. Days);Console. WriteLine(ts. Hours);Console. WriteLine(ts. Milliseconds);Console. WriteLine(ts. Minutes);Console. WriteLine(ts. Seconds);Console. WriteLine(ts. Ticks);Console. WriteLine(ts. TotalDays);Console. WriteLine(ts. TotalHours);Console. WriteLine(ts. TotalMilliseconds);Console. WriteLine(ts. TotalMinutes);Console. WriteLine(ts. TotalSeconds); in the duration. Similarly for the other “Total”-prepended properties. Just print out the values to get a feel of the differences. Now for a more specific and practical example. How do we calculate the number of days between two dates? DateTime dtStart dtEnd;TimeSpan ts;dtStart = new DateTime(2007. 2. 26);dtEnd = new DateTime(2007. 3. 2);ts = dtEnd - dtStart;Console. WriteLine(ts. TotalDays);dtStart = new DateTime(2008. 2. 26);dtEnd = new DateTime(2008. 3. 2);ts = dtEnd - dtStart;Console. WriteLine(ts. TotalDays); The above gives 4 days (26 Feb. 27 Feb. 28 Feb and 1 Mar) and 5 days (as before plus 29 Feb) respectively. Note that the leap years are also taken care of. The end date is not included in the calculation. Since the end date is at the very start of the day (0th hour. 0th minute. 0th second) it’s not counted as far as duration is concerned. But what if you need the number of months instead? How do you do it? Well you don’t need DateTime dtStart dtEnd;dtStart = new DateTime(2006. 11. 15);dtEnd = new DateTime(2007. 2. 15);int iNumberOfMonths = (dtEnd. Year * 12 + dtEnd. Month) - (dtStart. Year * 12 + dtStart. Month);Console. WriteLine(iNumberOfMonths); The DateTime. MinValue represents year 0001. January 1st on the 0th hour the 0th minute and 0th second. The DateTime. MinValue represents year 9999. December 31st on the 23rd hour the 59th minute and 59th second. XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Forex Groups - Tips on Trading

Related article:
http://polymathprogrammer.com/2007/11/02/using-and-formatting-datetime-and-timespan/

comments | Add comment | Report as Spam


"jtable - break toString() to get different rows" posted by ~Ray
Posted on 2008-03-12 23:10:48

I have a toString which returns the label place author and more things. I just be to alter the jtable that only shows the name but not the full toString(). Please help. this is really urgent!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! You seem to be here the first measure so let me give you a friendly advice: The problem is not at all urgent for anyone but you. Any pressure will cause to freeze some neurals in the brains of the persons reading and answering here and this may decrease the answering performance in the forum and can lead to overall missing a question (perhaps yours). You never say what is wrong what doesn't work so there is no way for any of us to help you. People on the forum help others voluntarily it's not their job. You need to help them back up you. Please learn how to ask questions first: http://faq javaranch com/java/HowToAskQuestionsOnJavaRanch Also your urgent!!!!!!!!!!!!!!!!!!!!!!!!!!!! statement gets us angry. Please don't use it. -> I just be to make the jtable that only shows the name but not the beat toString(). Then you need to extract the label from the full arrange. Only you know the format of your string so only you can answer the question. You could use something simply like a StringTokenizer or you could use the arrange indexOf(...) method to find your first delimiter and then use the Sring subString(...) method to get the name.

Forex Groups - Tips on Trading

Related article:
http://forum.java.sun.com/thread.jspa?threadID=5229276

comments | Add comment | Report as Spam


"jtable - break toString() to get different rows" posted by ~Ray
Posted on 2008-03-12 23:10:48

I have a toString which returns the name place author and more things. I just want to make the jtable that only shows the name but not the beat toString(). gratify help. this is really urgent!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! You seem to be here the first time so let me give you a friendly advice: The problem is not at all urgent for anyone but you. Any pressure ordain cause to stand still some neurals in the brains of the persons reading and answering here and this may reduce the answering performance in the forum and can bring about to overall missing a question (perhaps yours). You never say what is wrong what doesn't bring home the bacon so there is no way for any of us to back up you. People on the forum help others voluntarily it's not their job. You be to help them help you. gratify learn how to ask questions first: http://faq javaranch com/java/HowToAskQuestionsOnJavaRanch Also your urgent!!!!!!!!!!!!!!!!!!!!!!!!!!!! statement gets us angry. Please don't use it. -> I just be to make the jtable that only shows the name but not the full toString(). Then you need to remove the label from the beat string. Only you know the format of your string so only you can answer the question. You could use something simply like a StringTokenizer or you could use the String indexOf(...) method to find your first delimiter and then use the Sring subString(...) method to get the name.

Forex Groups - Tips on Trading

Related article:
http://forum.java.sun.com/thread.jspa?threadID=5229276

comments | Add comment | Report as Spam


"vb.net Argument 'Index' is not a valid value" posted by ~Ray
Posted on 2008-01-01 21:15:38

Hello it's been a while since I've posted on here. I be a little help with the error I'm receiving. A little history on the air... I've been trying to figure out how to retrieve and modify compose properties that I have in my membership profile for a specific user by user name. I couldn't see how using the merchandise profilemanager would allow me to directly display or edit any user property arrange. When I step through the code it errors on the line txt_FirstName text = dic_ProfileProperties("FirstName") tostring() Any help would be greatly appreciated. Here's the label: Private Sub fillUserProfile()Dim connstr As arrange = ConfigurationManager. ConnectionStrings("LMRConnectionString"). ConnectionStringDim channelise As SqlConnection = New SqlConnection(connstr)Dim sql As String = "decide aspnet_Users. UserName aspnet_compose. PropertyNames aspnet_Profile. PropertyValuesString FROM aspnet_Users INNER connect aspnet_Profile ON aspnet_Users. UserId = aspnet_Profile. UserId WHERE aspnet_Users. UserName = '" & GridViewMemberUser. SelectedValue. ToString() & "'"Dim cmd As New SqlCommand(sql conn)conn. Open()Dim reader As SqlDataReader = cmd. ExecuteReader()reader. Read()If reader. HasRows ThenDim userPropertyNames As String = reader("PropertyNames")Dim userPropertyString As String = reader("PropertyValuesString")If userPropertyNames <> "" ThenDim str_PropertyNames As Array = userPropertyNames. Split(":")Dim i As IntegerDim int_PropertyCount As Integer = UBound(str_PropertyNames)Dim dic_ProfileProperties As New Collection()Dim strkeyName As StringDim strkeyType As StringDim strkeyStart As StringDim strkeyEnd As StringDim strProperty As StringFor i = 0 To int_PropertyCount go 4If i < int_PropertyCount ThenstrkeyName = str_PropertyNames(i)strkeyType = str_PropertyNames(i + 1)strkeyStart = str_PropertyNames(i + 2)strkeyEnd = str_PropertyNames(i + 3)strProperty = userPropertyString. Substring(CInt(strkeyStart). CInt(strkeyEnd))dic_ProfileProperties. Add(strkeyName strProperty)End IfNexttxt_affiliate. Text = dic_ProfileProperties("affiliate"). ToString()txt_FirstName. Text = dic_ProfileProperties("FirstName"). ToString()txt_LastName. Text = dic_ProfileProperties("LastName"). ToString()txt_Address1. Text = dic_ProfileProperties("Address1"). ToString()txt_communicate2. Text = dic_ProfileProperties("Address2"). ToString()txt_City. Text = dic_ProfileProperties("City")..

Forex Groups - Tips on Trading

Related article:
http://www.xtremevbtalk.com/showthread.php?t=289696

comments | Add comment | Report as Spam


"Enum Conversion." posted by ~Ray
Posted on 2007-12-15 15:03:32

In this affix I will demonstrate how to convert To String. String To and Value to. First of all let us create an enumeration: It seams that nothing can be easier. We easily can use method to alter to arrange. It would bring home the bacon fine if we try to alter Colors. color. Colors. Blue or Color. Red. However what if we try to convert to String value like this: The output will be ‘3′ instead of ‘Blue. color’. There are two ways we can solve this problem: In inspect you decorated your enumertion with but be to create the determine use or methods with format “D” for decimal form or “X” for hexadecimal one. 4: Console. WriteLine(Enum. change(typeof(Colors) myColor. “x”)); The method with format “D” ordain output ‘3′ and with change “X” ordain give us ‘00000003′. In the example above colorString must be inspect exactly. There’s an override for method where you can ask to ignore case. Update: Thanks to Omer Mor (see his mention below) who pointed out that we don’t have to invoke ToObject() method. We can simply direct value to Enum write. This entry was posted onOctober 19. 2007 at 7:29 amand is filed under. You can go any responses to this entry through the cater. You can or from your own site. To alter a value to enum. I accept a simple explicit cast will bring home the bacon: public Colors Value2Enum(int colorValue){ return (Colors)colorValue;} Thanks for the mention. It’s not just simpler it’s also more efficient way. When you use ToObject you’ll have an extra unboxing. I can’t accept that I didn’t put it in my blog originally because when I have to deal with Enum types in my code. I don’t label ToObject. I use simple casting just desire you suggested. <a href="" call=""> <abbr title=""> <acronym title=""> <b> <blockquote have in mind=""> <have in mind> <code> <del datetime=""> <em> <i> <q cite=""> <touch> <strong>

Forex Groups - Tips on Trading

Related article:
http://vkreynin.wordpress.com/2007/10/19/enum-conversion/

comments | Add comment | Report as Spam


"cast Double to String in java" posted by ~Ray
Posted on 2007-12-09 13:37:50

Double to String casting …if you be to display its arrange in number change (like this ###,###,##0.00) do not use these lines … manifold sk = 12300000000.35; System out println(sk toString()); System out println(String valueOf(sk)); they would result like these ones: 1.230000000035E101.230000000035E10 Double sk = 12300000000.35; NumberFormat nm = NumberFormat getNumberInstance(); System out println(nm change(sk)); the latter prove would be this:

Forex Groups - Tips on Trading

Related article:
http://oohbegitu.wordpress.com/2007/10/26/cast-double-to-string-in-java/

comments | Add comment | Report as Spam


"cast Double to String in java" posted by ~Ray
Posted on 2007-12-09 13:37:39

Double to String casting …if you want to show its arrange in number format (like this ###,###,##0.00) do not use these lines … Double sk = 12300000000.35; System out println(sk toString()); System out println(String valueOf(sk)); they would prove desire these ones: 1.230000000035E101.230000000035E10 Double sk = 12300000000.35; NumberFormat nm = NumberFormat getNumberInstance(); System out println(nm format(sk)); the latter result would be this:

Forex Groups - Tips on Trading

Related article:
http://oohbegitu.wordpress.com/2007/10/26/cast-double-to-string-in-java/

comments | Add comment | Report as Spam


 

 




blogs - aa blogs - air force blogs - aquarius blogs - aries blogs - army blogs - arts blogs - baby blogs - blogs 4 men - blogs 4 women - cancer blogs - capricorn blogs - career change blogs - choice blogs - christmas blogs - cigar blogs - cigarette blogs - cig blogs - coast guard blogs - coffee bean blogs - college baseball blogs - college basketball blogs - college football blogs - colleges blogs - computer blogs - create blogs - dating blogs - elvis blogs - email chat blogs - email pal blogs - enhancement blogs - fall blogs - fha blogs - freedom blogs - friendly blogs - funny blogs - gambler blogs - gemini blogs - her blog - his blog - hockey blogs - join blogs - javas blogs - kid safe blogs - leo blogs - libra blogs - apartments blogs - coffees blogs - horoscopes blogs - life advice blogs - lover blogs - marine blogs - married blogs - military blogs - misc blogs - more money blogs - mortgage blogs - move blogs - movies blogs - musical blogs - navy blogs - new in town blogs - obscure blogs - online date blogs - online game blogs - over 30 blogs - over 40 blogs - over 50 blogs - over 60 blogs - over 70 blogs - over 80 blogs - over 90 blogs - password blogs - pc blogs - mortgages blogs - peoples blogs - pictures blogs - pipe blogs - pisces blogs - poems blogs - poker blogs - police blogs - political blogs radio blogs - read blogs - recreational vehicle blogs - relocation blogs - reserve blogs - rv blogs - safe blogs - scorpio blogs - singles blogs - smokers blogs - smoker blogs - state blogs - state college blogs - taurus blogs - teen advice blogs - teenager blogs - tobacco blogs - tv blogs - vacation blogs - veteran blogs - virgo blogs - virtual blogs - weekly blogs - wingman blogs - word blogs - words blogs - writer blogs - poetry blogs - prescription blogs - sagittarius blogs - straight blogs - summer blogs - gi blogs - hooka blogs - penis enlargement blogs - vfw blogs - casinos blogs - casino blogs - web hosting blogs - hosting blogs - auto blogs - truck blogs - van blogs - suv blogs - 4 wheel blogs - harley blogs - flu blogs - diet blogs - pistols blogs - teenage blogs - lpga blogs - burnable blogs - new tunes blogs - coaching blogs - treasures blogs - trades blogs - nutty blogs - skate blogs - play 21 blogs - weather blogs - poker players - golf blogs - american blogs - football blogs - baseball blogs - hockey blogs - basketball blogs - soccer blogs - cooking blogs - recipe blogs - space blogs - 3d games blogs - barbecue blogs




the tostring archives:

11 articles in 2006-01
22 articles in 2006-02
27 articles in 2006-03
36 articles in 2006-04
27 articles in 2006-05
26 articles in 2006-06
24 articles in 2006-07
18 articles in 2006-08
22 articles in 2006-09
30 articles in 2006-10
22 articles in 2006-11
22 articles in 2006-12
12 articles in 2007-01
12 articles in 2007-02
3 articles in 2007-03
7 articles in 2007-04
11 articles in 2007-05
10 articles in 2007-06
3 articles in 2007-07
1 articles in 2007-09




next page


tostring