How to force a time format regardless of regional settings.

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
PatrickJacquesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PatrickJacquesAuthor Commented:
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
PockyMasterCommented:
You can set the local settings for your app environment by using the globalization namespaces.

0
PatrickJacquesAuthor Commented:
Can you clarify? I never used this function before..

Thanks for your help.
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

g_johnsonCommented:
date.now.tostring("HHMMss")
0
PockyMasterCommented:

'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
PockyMasterCommented:
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
PatrickJacquesAuthor Commented:
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
PatrickJacquesAuthor Commented:
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
PockyMasterCommented:
Let me try it for you..wait a mom
0
PatrickJacquesAuthor Commented:
God dawm it.. I think I just found out...newbie issue, sorry for the disturbance.
0
PatrickJacquesAuthor Commented:
I simply had to select Custom in the Format of the DateTimePicker instead of Time....
0
PockyMasterCommented:
There you go :D

Also use the Value instead of Text (that will provide you with a DateTime obj, instead of String)
0
PatrickJacquesAuthor Commented:
In what way is it better?
0
PockyMasterCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PatrickJacquesAuthor Commented:
Alright, thanks I appreciate your help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.