Link to home
Start Free TrialLog in
Avatar of SaltyDawg
SaltyDawgFlag for United States of America

asked on

DateTime format

I need to get the date time for entry into the mysql database.

            DateTime localTime = DateTime.Now.ToUniversalTime();
            localTime = localTime.AddHours(7);
            strDate = localTime.ToString("yyyy-MM-dd HH:mm:ss");

Have all that working, but now I'm trying to figure out how to make the time show 24 hours instead of 12 hours. example I need 16:00:00 instead of 04:00:00.

Also I will always need the time in Eastern Time. I used the AddHours method adding 7, will this consistently give me the right Eastern Time? Is this a good method?
ASKER CERTIFIED SOLUTION
Avatar of jandromeda
jandromeda
Flag of Sri Lanka image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SaltyDawg

ASKER

I am using this

            DateTime localTime = DateTime.Now;
            strDate = localTime.ToString("yyyy-MM-dd HH:mm:ss");

It's working, can someone confirm that I will have no issues? Does this using the PC's clock, I'd just have to insure that the user has the correct time.
That will use the machine clock, and convert it to 24-hour format.

Bob