| | |
date and time format and how to add
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Mar 2008
Posts: 63
Reputation:
Solved Threads: 0
i know that the datetime.utcnow command is to show the date and time of the instant it was called.
just say i have this
what is the code or the numbers i need to use for this?
just say i have this
C# Syntax (Toggle Plain Text)
int time; time = //27/08/2009 09:00:00 time = time + //15 seconds
what is the code or the numbers i need to use for this?
Use the TimeSpan class and the overloaded + operator.
c# Syntax (Toggle Plain Text)
TimeSpan FifteenSecs = new TimeSpan(0, 0, 15); time = time + FifteenSecs;
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
In addition to the timespan you can also add dates using the DateTime class:
C# Syntax (Toggle Plain Text)
DateTime utcNow = DateTime.UtcNow.AddSeconds(15);
In your first code sample you used an int as type for your time variable, that is not correct.
Use this (just as Scott suggested already) DateTime time = DateTime.UtcNow;
Now you can say things like time.AddSeconds(15); or use a TimeSpan like I did.
Use this (just as Scott suggested already) DateTime time = DateTime.UtcNow;
Now you can say things like time.AddSeconds(15); or use a TimeSpan like I did.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
•
•
Join Date: Mar 2008
Posts: 63
Reputation:
Solved Threads: 0
i have this in a string:
"DATA COLLECTED FOR 24 HOURS STARTING AT: 09:00:00 Hrs 27-08-09"
how would i go about making it "27-08-09 09:00:00"
i have a rough idea with splits and trims etc but i dont actually know how i would get both beside each other. perhaps putting each word in a string, finding out which ones it is then printing out a string made up of the elements containing them?
"DATA COLLECTED FOR 24 HOURS STARTING AT: 09:00:00 Hrs 27-08-09"
how would i go about making it "27-08-09 09:00:00"
i have a rough idea with splits and trims etc but i dont actually know how i would get both beside each other. perhaps putting each word in a string, finding out which ones it is then printing out a string made up of the elements containing them?
If you know your string is ALWAYS of the same format you could use:
c# Syntax (Toggle Plain Text)
string input = "DATA COLLECTED FOR 24 HOURS STARTING AT: 09:00:00 Hrs 27-08-09"; string dateStr = input.Substring(input.Length - 8, 8); string timeStr = input.Substring(input.Length - 21, 8); string datetimeStr = dateStr + " " + timeStr;
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
![]() |
Similar Threads
- how to convert date to mysql format (VB.NET)
- I want to retrieve only date from date/time (JSP)
- Excel Date/Time Format (Visual Basic 4 / 5 / 6)
- ho to change date and time format to insert into database? (PHP)
- how can add date in vb.net form (VB.NET)
- date-time problem (C++)
Other Threads in the C# Forum
- Previous Thread: URGENT ADODB.Recordset adVariant problem
- Next Thread: Convert words into numbers
| Thread Tools | Search this Thread |
.net access ado.net algorithm array backup barchart bitmap box broadcast buttons c# chat check checkbox client color combobox control conversion csharp custom database datagrid datagridview dataset datetime decryption degrees development draganddrop drawing encryption enum event excel file files form format forms function gdi+ httpwebrequest i18n image imageprocessing index input install java label list listbox listener mandelbrot math mouseclick mysql operator path photoshop picturebox pixelinversion post programming radians regex remote remoting richtextbox saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer update uploadatextfile usercontrol users validation view visualstudio webbrowser whileloop windows winforms wpf xml






