AM PM does not appear on page

R

Razak

I wonder if any of you have had this problem before. I have a variable dt
which reads the scmalldatetime field in the database. I want to show the
date & time on aspx page in the format 'dd/MM/yyyy hh:mm tt' using this
statement:

dt.ToString("dd/MM/yyyy hh:mm tt")

But the AMPM designators does not appear. Other parts of the date & time can
be determined using the format string except the AMPM designator. The
regional setting of both my pc and the server have the AM PM symbol set
correctly.

I've even tried hard-coded the time to show be shown the page like this:

Dim dt As DateTime = #10/5/1971 5:38:00 PM#
Dim sdt As String = dt.ToString("dd/MM/yyyy hh:mm tt")
lblDateTaken.Text = sdt

And the date is shown as 05/10/1971 05:38

Is there anything I should do to make them appear the way I want?

thx
 
R

Razak

Nope.. they still does not appear...
It still shows : 05/10/1971 05:38


----------------------------------------------------------------------------
---- -----------------------------------------------------------------------
---------
Ken Cox said:
Hi Razak,

You want the Format function to get what you need:

Dim dt As DateTime = #10/5/1971 5:38:00 PM#
Dim sdt As String '= dt.ToString("dd/MM/yyyy hh:mm tt")
sdt = Format(dt, "dd/MM/yyyy hh:mm tt")
lblDateTaken.Text = sdt

Returns 05/10/1971 05:38 PM

http://msdn.microsoft.com/library/d...us/vblr7/html/vafmtuserdefineddateformats.asp

Does this help?

Ken
Microsoft MVP [ASP.NET]


Razak said:
I wonder if any of you have had this problem before. I have a variable dt
which reads the scmalldatetime field in the database. I want to show the
date & time on aspx page in the format 'dd/MM/yyyy hh:mm tt' using this
statement:

dt.ToString("dd/MM/yyyy hh:mm tt")

But the AMPM designators does not appear. Other parts of the date & time
can
be determined using the format string except the AMPM designator. The
regional setting of both my pc and the server have the AM PM symbol set
correctly.

I've even tried hard-coded the time to show be shown the page like this:

Dim dt As DateTime = #10/5/1971 5:38:00 PM#
Dim sdt As String = dt.ToString("dd/MM/yyyy hh:mm tt")
lblDateTaken.Text = sdt

And the date is shown as 05/10/1971 05:38

Is there anything I should do to make them appear the way I want?

thx
--------------------------------------------------------------------------
 
H

Hans Kesting

Razak said:
I wonder if any of you have had this problem before. I have a variable dt
which reads the scmalldatetime field in the database. I want to show the
date & time on aspx page in the format 'dd/MM/yyyy hh:mm tt' using this
statement:

dt.ToString("dd/MM/yyyy hh:mm tt")

But the AMPM designators does not appear. Other parts of the date & time can
be determined using the format string except the AMPM designator. The
regional setting of both my pc and the server have the AM PM symbol set
correctly.

the "tt" format is specified (in MSDN) as

The AM/PM designator defined in AMDesignator or PMDesignator, if any.

(that's a "DateTimeFormatInfo.AMDesignator")

could it be that you (or rather the aspnet process) use a culture that doesn't
have an AMDesignator (or an empty one)?
What it the value of DateTimeInfo.CurrentInfo.AMDesignator ?


Hans Kesting
 
R

Razak

It appears that the AMDesignator and PMDesignator is empty. How to set it
since they are read-only?

On the server, I've set the designators accordingly in the Regional
settings.
 
H

Hans Kesting

Razak said:
It appears that the AMDesignator and PMDesignator is empty. How to set it
since they are read-only?

On the server, I've set the designators accordingly in the Regional
settings.

IIRC, the regional settings are user-specific. So if *you* set them (using *your* account)
then the ASPNET user ('NETWORK SERVICES' for Win2003?) still uses it's original
version.

Do you change the "culture" somewhere in your application?

Try this:
dt.ToString("dd/MM/yyyy hh:mm tt", DateTimeFormatInfo.InvariantInfo);

Hans Kesting
 
R

Razak

Nope, I didnt change any culture anywhere in my app. Anyway, I have found
the way to customize the am/pm designator. It's based on the current thread
though, so I have to put then code in a function and call it whenever I need
to display the formatted date & time.

Public Shared Function GetDateTimeString(ByVal dt As Date) As String
Dim myOCI, myCCI As CultureInfo

myCCI = myOCI.CurrentCulture().Clone()
myCCI.DateTimeFormat.PMDesignator = "pm"
myCCI.DateTimeFormat.AMDesignator = "am"
Thread.CurrentThread.CurrentCulture = myCCI

Return Format(dt, "dd/MM/yyyy hh:mm tt")
End Function

Thanks for your response..
 
K

Ken Cox [Microsoft MVP]

Curious.

You might want to use this to determine what culture your system is set to.

lblDateTaken.Text = Thread.CurrentThread.CurrentCulture.EnglishName & _
":" & Thread.CurrentThread.CurrentUICulture.EnglishName

Ken
 
R

Razak

It's Date taken: Malay (Malaysia):English (United States)

I remember setting my server to Malay(Malaysia) before, but have changed it
to English(UK).
Could that be the problem? Perhaps Malay culture setting has no AM/PM
Designators set.
 
K

Ken Cox [Microsoft MVP]

Could be. I was surprised when my code didn't produce the expected result on
your system!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top