Solved

asp.net formatting military time

Posted on 2004-08-23
12
658 Views
Last Modified: 2012-06-21
I want to show short date 9/15/04 and military time 23:10

What would I do to convert this my TextTimeIn.Value to that format?

If Not row.IsTimeInNull Then Me.TextTimeIn.Value = row.TimeIn

Its' currently showing this: 8/21/2004 2:38:09 PM

0
Comment
Question by:jamesh1031
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +1
12 Comments
 

Author Comment

by:jamesh1031
ID: 11873362
This data is stored in one field (date and time) (MS Sql)
0
 
LVL 2

Assisted Solution

by:netjkus
netjkus earned 100 total points
ID: 11873425
string dtformat = "MM/dd/YYYY HH:mm:ss";

string Timenow = DateTime.Now.ToString(dtformat);

Note the Capital HH - makes it 24 hour format.

any question email me.
0
 
LVL 2

Expert Comment

by:netjkus
ID: 11873441
Or if you need to convert a datetime existing, eg.

 Datetime Dttest = GetdatetimefromDBfield();

dttest.ToString(dtformat);
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jamesh1031
ID: 11873466
So, how do add it to the page?

If Not row.IsTimeInNull Then Me.TextTimeIn.Value = row.TimeIn
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11873594
Hi there,
use...
     If Not row.IsTimeInNull Then Me.TextTimeIn.Value = Format(CType(row.TimeIn , Date), "HH:mm")

-Baan
0
 
LVL 3

Expert Comment

by:gspronych
ID: 11887671
Hi

I found the easiest way to change date formats by changing the page culture.

Click the page, and scroll down to culture in the properties window.
Change the culture to this property for your formatting: en-GB English (United Kingdom)
This culture will shows dates in this format '24/08/2004 16:09:42'
Changing the culture will display times as described by each culture.

Localization can be done project wide, or page specific as I described above.
0
 

Author Comment

by:jamesh1031
ID: 11887902
I couldn't get dotnetlover's method to work....i don't have anywhere where I see "culture" in visual studio.net in a properties window..i may post the question at sql as I want to make sure that the display format won't mess up the db data when saving.
0
 
LVL 3

Accepted Solution

by:
gspronych earned 300 total points
ID: 11888110
To manually add a culture to a page, add the culture keyword to your page directive.
Click the html tab to view the html version of your page.

Then add this value at the top of the page
culture="en-GB"

My page directive looks like this

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="RTF.aspx.vb" Inherits="Secure.RTF" culture="en-GB"%>

It's worth a try


0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11888277
>> "I couldn't get dotnetlover's method to work"<<  
what is the error you are geting ?
0
 

Author Comment

by:jamesh1031
ID: 11888808
no error, just didn't format the date and time.

0
 
LVL 18

Assisted Solution

by:DotNetLover_Baan
DotNetLover_Baan earned 100 total points
ID: 11889042
Hi there...
if you want to change your culture from code....

Imports System.Globalization
Imports System.Threading

Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US")

Then use my earlier post...
visit this link...  http://www.microsoft.com/globaldev/getWR/steps/wrg_date.mspx
-Baan
0
 

Author Comment

by:jamesh1031
ID: 11889154
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

736 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question