?
Solved

How to force a time format regardless of regional settings.

Posted on 2006-04-05
15
Medium Priority
?
264 Views
Last Modified: 2012-08-14
Hi, I'm trying to write a program that reads timeframes from an ini file and after a change by the user, it saves back the information to the ini file. The thing is that I want to keep a constant format so that it will always read the right information. This is how I want the ini file :

[Time]
Dim=02:20:00 AM-08:00:00 PM
Lun=02:20:00 AM-09:00:00 PM
Mar=03:20:00 AM-10:00:00 PM
Mer=04:20:00 AM-11:00:00 PM
Jeu=05:20:00 AM-01:00:00 PM
Ven=06:20:00 AM-02:00:00 PM
Sam=07:20:00 AM-03:00:00 PM

so that when I read the file I can set the dateTimePicker properly using this :

Case currentline.Contains("Dim=")

                                timeSunBegin.Text = currentline.Substring(4, 11)
                                timeSunEnd.Text = currentline.Substring(16, 11)

The problem is that if my regional settings is set to h:mm:ss tt it won't show me the first digit if it's a zero. So when I write back to the ini file, it misses one digit.... I would like to force a format so that I keep the first digit regardless of what is set in the regional settings of the computer.

Any ideas?? Thanks
0
Comment
Question by:PatrickJacques
  • 8
  • 6
15 Comments
 

Author Comment

by:PatrickJacques
ID: 16383788
By the way, I already tried to use String.Format(timeSunBegin.Text, "hh:mm:ss tt") when I write back to the file, but it doesn't do the trick, it still shows me 2:20:40 AM instead of 02:00:40 AM

Thanks
0
 
LVL 14

Expert Comment

by:PockyMaster
ID: 16383818
You can set the local settings for your app environment by using the globalization namespaces.

0
 

Author Comment

by:PatrickJacques
ID: 16383848
Can you clarify? I never used this function before..

Thanks for your help.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 4

Expert Comment

by:g_johnson
ID: 16383894
date.now.tostring("HHMMss")
0
 
LVL 14

Expert Comment

by:PockyMaster
ID: 16383935

'your current settings
  MessageBox.Show(CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern)
'your time with your current settings
  MessageBox.Show(Now.ToShortTimeString())
'clone your culture
    Dim ci As CultureInfo = Application.CurrentCulture.Clone
'modify it
  ci.DateTimeFormat.ShortTimePattern = "hh:MM:ss"
   Application.CurrentCulture = ci

'did it work?
       MessageBox.Show(Now.ToShortTimeString())
0
 
LVL 14

Expert Comment

by:PockyMaster
ID: 16383947
You also can override different properties that way, and your application will keep on using it, as long as you stay in the same thread
0
 

Author Comment

by:PatrickJacques
ID: 16384025
Thanks PockyMaster, I think we're getting close to it, but still does not work. Here's what I have :

        Dim ci As CultureInfo = Application.CurrentCulture.Clone
        ci.DateTimeFormat.ShortTimePattern = "hh:MM:ss tt"
        Application.CurrentCulture = ci


        'Update TimeFrame
            CompleteText = CompleteText.Replace(CompleteText.Substring(72, 23), timeSunBegin.Text + "-" + timeSunEnd.Text)
            MsgBox(timeSunBegin.Text)
            MsgBox(CompleteText)

and the first msgbox shows me 2:20:40 AM instead of 02:20:40.

Thanks
0
 

Author Comment

by:PatrickJacques
ID: 16384051
I guess I have to format my DateTimePicker too.. but I don't know how.. it does not show the first digit. Is there a way to force it ? I saw the customFormat property but does not do anything.

Thanks
0
 
LVL 14

Expert Comment

by:PockyMaster
ID: 16384060
Let me try it for you..wait a mom
0
 

Author Comment

by:PatrickJacques
ID: 16384082
God dawm it.. I think I just found out...newbie issue, sorry for the disturbance.
0
 

Author Comment

by:PatrickJacques
ID: 16384089
I simply had to select Custom in the Format of the DateTimePicker instead of Time....
0
 
LVL 14

Expert Comment

by:PockyMaster
ID: 16384120
There you go :D

Also use the Value instead of Text (that will provide you with a DateTime obj, instead of String)
0
 

Author Comment

by:PatrickJacques
ID: 16384189
In what way is it better?
0
 
LVL 14

Accepted Solution

by:
PockyMaster earned 375 total points
ID: 16384214
You will not lose the datatype until you present it to the user, in that way you can still decide at anytime to present it one time as a date, later as a time, or whatever format you like to use, but once it's a text.. you need to do some work to get back that information.
0
 

Author Comment

by:PatrickJacques
ID: 16384388
Alright, thanks I appreciate your help.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

850 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