Answered by:
time separator

Question
-
User-336392218 posted
On my machine if I write:
Response.Write(DateTime.Now.ToString(New Globalization.CultureInfo("it-IT")))
the output is for example:16/09/2010 11:16:39
this is good for the date part that according to "it-IT" culture should be dd/MM/yyyy (day, month, year)
but the time part, i think, is not right because the time separator for italian culture should be the "." not the ":"
environment:
web site application
.net 4.0
win 7 professional
many thanks for any help.
Thursday, September 16, 2010 5:32 AM
Answers
-
User-1179452826 posted
If you wish to force an output, you can do this:
DateTime.Now.ToString("dd/MM/yyyy hh.mm.ss") //outputs time with . separator
DateTime.Now.ToString("dd/MM/yyyy hh-mm-ss") //outputs time with - separator
DateTime.Now.ToString("dd-MM-yyyy hh#mm#ss") //outputs time with # separator and date with - separator
and so on.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, September 16, 2010 9:12 AM -
User-25924017 posted
I tried your 2 lines of code:I can not reproduce, works fine here, I have no idea why it ignores the setting in formatinfo at your end,something must be very specific to your machine. can you test your code on another machine?Just change time format setting for Italian in control panel and see how your code reacts with above 2 lines, otherwise force a time separator,wherever you use it.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, September 16, 2010 9:28 AM
All replies
-
User-25924017 posted
Weird, never saw something like that until and unless you have customized format in your culture and regional settings in Control Panel, if so
then use it like this, set UseUserOverride to false.
Response.Write(DateTime.Now.ToString(New Globlization.CultureInfo("it-IT",false)));
Thursday, September 16, 2010 7:02 AM -
User-1802908944 posted
use it
Response.Write(DateTime.Parse(DateTime.Now.ToString("dd/MM/yyyy"), new CultureInfo("it-IT")).ToString("dd/MM/yyyy"));
Thursday, September 16, 2010 7:14 AM -
User-336392218 posted
thank for your quick reply!
you'r right. my default setting in control panel use italian culture with time separator equal to ":".
This is a new machine and I never changed the default setting.
but your code doesn't help, the output is still with the ":" as time separator.
Thursday, September 16, 2010 7:34 AM -
Thursday, September 16, 2010 7:35 AM
-
Thursday, September 16, 2010 7:39 AM
-
User-336392218 posted
Hi Tapan Bhatt ,
following the link I tried the code:
Protected Overloads Overrides Sub InitializeCulture() Dim objCultureInfo As New CultureInfo("el-GR", False) Thread.CurrentThread.CurrentUICulture = objCultureInfo Thread.CurrentThread.CurrentCulture = objCultureInfo objCultureInfo = Nothing MyBase.InitializeCulture() End Sub
but it doesn't help.
Thursday, September 16, 2010 7:55 AM -
User-25924017 posted
thank for your quick reply!
you'r right. my default setting in control panel use italian culture with time separator equal to ":".
This is a new machine and I never changed the default setting.
but your code doesn't help, the output is still with the ":" as time separator.
Okay as suspected,
Look at example below,here if I twist the useUserOverride, I see different time separator. (its in C# so convert to VB.net)
DateTimeFormatInfo dmt = new CultureInfo("it-IT",false).DateTimeFormat;dmt.TimeSeparator="-";Response.Write(DateTime.Now.ToString(dmt));DateTimeFormatInfo dmt = new CultureInfo("it-IT",false).DateTimeFormat;
dmt.TimeSeparator="-";
Response.Write(DateTime.Now.ToString(dmt));
Can;t see what are you doing different.
Thursday, September 16, 2010 8:15 AM -
User-336392218 posted
SSA,
your code works but explicitly setting the TimeSeparator in the code is something that I would like to avoid.
I prefer to change this kind of settings from the web.config file, where I also putted the Globalization Element:
<globalization uiCulture="it" culture="it-IT" />
Is there a way to set the TimeSeparator in the web.config file?
Thursday, September 16, 2010 8:38 AM -
User-25924017 posted
SSA,
your code works but explicitly setting the TimeSeparator in the code is something that I would like to avoid.
No I am not telling you to set it explicitly but an example to show how UseUserOverride affect things,
For your issue, I modified time format for Italian culture in my regional settings, to use ':' as time seperator
then in web.config same as yours: <globalization uiCulture="it" culture="it-IT" />
in code I do like this, so it should avoid use custom setting, as I don't allow user overrides here
DateTimeFormatInfo dmt = new CultureInfo("it-IT",false).DateTimeFormat;//dmt.TimeSeparator="#";Response.Write(DateTime.Now.ToString(dmt));DateTimeFormatInfo dmt = new CultureInfo("it-IT",false).DateTimeFormat;
Response.Write(DateTime.Now.ToString(dmt));
This gives me '.' as seperator and ':' when useuseroverride is set to true. you can not set it in web.config but try above 2 lines. Don't use custom time separator and see.
Thursday, September 16, 2010 8:45 AM -
User-336392218 posted
SSA,
your code works but explicitly setting the TimeSeparator in the code is something that I would like to avoid.
No I am not telling you to set it explicitly but an example to show how UseUserOverride affect things,
For your issue, I modified time format for Italian culture in my regional settings, to use ':' as time seperator
then in web.config same as yours: <globalization uiCulture="it" culture="it-IT" />
in code I do like this, so it should avoid use custom setting, as I don't allow user overrides here
DateTimeFormatInfo dmt = new CultureInfo("it-IT",false).DateTimeFormat;//dmt.TimeSeparator="#";Response.Write(DateTime.Now.ToString(dmt));DateTimeFormatInfo dmt = new CultureInfo("it-IT",false).DateTimeFormat;
Response.Write(DateTime.Now.ToString(dmt));
This gives me '.' as seperator and ':' when useuseroverride is set to true. you can not set it in web.config but try above 2 lines. Don't use custom time separator and see.
I tried your 2 lines of code:
Dim dmt As Globalization.DateTimeFormatInfo = New Globalization.CultureInfo("it-IT", False).DateTimeFormat Response.Write(DateTime.Now.ToString(dmt))
but I always obtain the ":" separator, both using False or True for UseUserOverride parameter.
Thursday, September 16, 2010 9:01 AM -
User-1179452826 posted
If you wish to force an output, you can do this:
DateTime.Now.ToString("dd/MM/yyyy hh.mm.ss") //outputs time with . separator
DateTime.Now.ToString("dd/MM/yyyy hh-mm-ss") //outputs time with - separator
DateTime.Now.ToString("dd-MM-yyyy hh#mm#ss") //outputs time with # separator and date with - separator
and so on.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, September 16, 2010 9:12 AM -
User-336392218 posted
If you wish to force an output, you can do this:
DateTime.Now.ToString("dd/MM/yyyy hh.mm.ss") //outputs time with . separator
DateTime.Now.ToString("dd/MM/yyyy hh-mm-ss") //outputs time with - separator
DateTime.Now.ToString("dd-MM-yyyy hh#mm#ss") //outputs time with # separator and date with - separator
and so on.
definitely yes!
but in the msdn online under "Custom Date and Time Format String" you can read:
The ":" custom format specifier represents the time separator, which is used to differentiate hours, minutes, and seconds. The appropriate localized time separator is retrieved from the DateTimeFormatInfo.TimeSeparator property of the current or specified culture.
Thursday, September 16, 2010 9:25 AM -
User-25924017 posted
I tried your 2 lines of code:I can not reproduce, works fine here, I have no idea why it ignores the setting in formatinfo at your end,something must be very specific to your machine. can you test your code on another machine?Just change time format setting for Italian in control panel and see how your code reacts with above 2 lines, otherwise force a time separator,wherever you use it.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, September 16, 2010 9:28 AM