How can I format numbers with leading zeros? I believe I did this before
some time ago but I cannot remember how I did it.
I want the output be 100305 for 10:03:05.
string fname = string.Format("{0}{1}{2}.txt", dt.Hour, dt.Minute,
dt.Second);
I do not want to use ToString() because it generated to much temporary
objects, and DateTime.ToShortTimeString() is culture dependend and contains
colon characters.
--
cody
Freeware Tools, Games and Humour http://www.deutronium.de.vu || http://www.deutronium.tk 3 9650
use string.Format("{0:hh}{0:mm}{0:ss}.txt", dt);
or
use string.Format("{0:HH}{0:mm}{0:ss}.txt", dt);
/LM
"cody" <no****************@gmx.net> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl... How can I format numbers with leading zeros? I believe I did this before some time ago but I cannot remember how I did it. I want the output be 100305 for 10:03:05.
string fname = string.Format("{0}{1}{2}.txt", dt.Hour, dt.Minute, dt.Second);
I do not want to use ToString() because it generated to much temporary objects, and DateTime.ToShortTimeString() is culture dependend and contains colon characters.
-- cody
Freeware Tools, Games and Humour http://www.deutronium.de.vu || http://www.deutronium.tk
Cody,
I would use: string fname = string.Format("{0:HHmmss}.txt", dt);
NOTE: HH above formats hour as 00-23, hh formats hour as 01-12.
Alternatively you can use:
string fname = string.Format("{0:D2}{1:D2}{2:D2}.txt", dt.Hour, dt.Minute, dt.Second);
For documentation on what is allowed & how to use String.Format see: http://msdn.microsoft.com/library/de...ttingtypes.asp
Hope this helps
Jay
"cody" <no****************@gmx.net> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl... How can I format numbers with leading zeros? I believe I did this before some time ago but I cannot remember how I did it. I want the output be 100305 for 10:03:05.
string fname = string.Format("{0}{1}{2}.txt", dt.Hour, dt.Minute, dt.Second);
I do not want to use ToString() because it generated to much temporary objects, and DateTime.ToShortTimeString() is culture dependend and contains colon characters.
-- cody
Freeware Tools, Games and Humour http://www.deutronium.de.vu || http://www.deutronium.tk
> > string fname = string.Format("{0:HHmmss}.txt", dt); NOTE: HH above formats hour as 00-23, hh formats hour as 01-12.
Alternatively you can use:
string fname = string.Format("{0:D2}{1:D2}{2:D2}.txt", dt.Hour,
dt.Minute, dt.Second);
thanks thats exactly what I was looking for!
--
cody
Freeware Tools, Games and Humour http://www.deutronium.de.vu || http://www.deutronium.tk This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Krakatioison |
last post by:
My sites navigation is like this:
http://www.newsbackup.com/index.php?n=000000000040900000
, depending on the variable "n" (which is always a number), it will take me
anywhere on the site......
|
by: Stian |
last post by:
Hi, I'm sort of new to Python and I've just discovered the amazing
formatting using the % operator. One thing I can't figure out is how
to format numbers so that they get leading zeros, for example...
|
by: Dave Brydon |
last post by:
Access 2003
I have a combo box in my personnel table, which draws its data from a trade
code table; the original field in the code table, is numeric, Long Integer,
and formatted with 5 zero's . ...
|
by: cody |
last post by:
How can I format numbers with leading zeros? I believe I did this before
some time ago but I cannot remember how I did it.
I want the output be 100305 for 10:03:05.
string fname =...
|
by: Bilgehan.Balban |
last post by:
Hi,
I use %#08x to print unsigned integers in hexadecimal format. According
to C ref. man. Harbison & Steele, #08 stands for "pad the number with
up to 8 zeroes to complete it to 8 digit...
|
by: chris |
last post by:
Hi,
I have a simple ms access application that allows you to scan barcodes
in to a form which stores them in the database. The barcodes are 6
digits in length e.g. 555666 but my handheld...
|
by: Code::Tyr |
last post by:
Hello. I have a simple problem and need help. I am developing a simple
file system that stores info based on folder names. Now, I only have
one problem. How do i format (int i = 2) into a string...
|
by: Vlinder |
last post by:
I'm completely new to PHP (jumped ship this week from MSAccess and ASP to MySql and PHP) and I'd appreciate some help with leading zeros in telephone numbers.
I've got a field with type...
|
by: lawpoop |
last post by:
Hello all --
I'm trying to format decimal numbers for a report. I would have to
have the number with leading zeros to the tens' place, and trailing
zeros to the thousandths' place.
I'm using...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
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...
| |