Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,470 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,540 people online right now. Registration is fast and FREE... Join Now!




how to get current time

 
Reply to this topicStart new topic

how to get current time, how to get current time and get d values hh/mm/ss in different intege

azeeejaz
1 Jul, 2008 - 11:03 PM
Post #1

New D.I.C Head
*

Joined: 1 Jul, 2008
Posts: 1


hi i want to get current time and date in integer values plz help me
fnx alot
User is offlineProfile CardPM
+Quote Post

3DrunkPandas
RE: How To Get Current Time
2 Jul, 2008 - 04:46 AM
Post #2

New D.I.C Head
*

Joined: 6 Oct, 2007
Posts: 22


My Contributions
I think you have to create a new DateTime object and get its Now field.

CODE
DateTime myTime = new DateTime();
int hh = myTime.Now.hh;
int mm = myTime.Now.mm;
int ss = myTime.Now.ss;

User is offlineProfile CardPM
+Quote Post

eclipsed4utoo
RE: How To Get Current Time
2 Jul, 2008 - 04:51 AM
Post #3

D.I.C Regular
Group Icon

Joined: 21 Mar, 2008
Posts: 363



Thanked: 19 times
Dream Kudos: 25
My Contributions
QUOTE(3DrunkPandas @ 2 Jul, 2008 - 05:46 AM) *

I think you have to create a new DateTime object and get its Now field.

CODE
DateTime myTime = new DateTime();
int hh = myTime.Now.hh;
int mm = myTime.Now.mm;
int ss = myTime.Now.ss;



do people even try the code out before writing it? that code has 6 errors.

here is the correct code:

C#

int hours = DateTime.Now.Hour;
int minutes = DateTime.Now.Minute;
int seconds = DateTime.Now.Second;


This post has been edited by eclipsed4utoo: 2 Jul, 2008 - 04:52 AM
User is offlineProfile CardPM
+Quote Post

zakary
RE: How To Get Current Time
2 Jul, 2008 - 04:56 AM
Post #4

D.I.C Regular
Group Icon

Joined: 15 Feb, 2005
Posts: 405



Thanked: 6 times
Dream Kudos: 175
My Contributions
Maybe 3DrunkPandas forgot that there is no hh in DataTime that hh is used when converting DateTime to string and hh is a string format.
User is offlineProfile CardPM
+Quote Post

eclipsed4utoo
RE: How To Get Current Time
2 Jul, 2008 - 05:16 AM
Post #5

D.I.C Regular
Group Icon

Joined: 21 Mar, 2008
Posts: 363



Thanked: 19 times
Dream Kudos: 25
My Contributions
QUOTE(zakary @ 2 Jul, 2008 - 05:56 AM) *

Maybe 3DrunkPandas forgot that there is no hh in DataTime that hh is used when converting DateTime to string and hh is a string format.


he also forgot that the ".Now" property of the DateTime class is not accessible from an instance of the DateTime class.

User is offlineProfile CardPM
+Quote Post

3DrunkPandas
RE: How To Get Current Time
2 Jul, 2008 - 10:58 AM
Post #6

New D.I.C Head
*

Joined: 6 Oct, 2007
Posts: 22


My Contributions
QUOTE(eclipsed4utoo @ 2 Jul, 2008 - 06:16 AM) *

QUOTE(zakary @ 2 Jul, 2008 - 05:56 AM) *

Maybe 3DrunkPandas forgot that there is no hh in DataTime that hh is used when converting DateTime to string and hh is a string format.


he also forgot that the ".Now" property of the DateTime class is not accessible from an instance of the DateTime class.


Eh sry... I'm currently learning the language, so I'm far from being a professional.
User is offlineProfile CardPM
+Quote Post

eclipsed4utoo
RE: How To Get Current Time
2 Jul, 2008 - 11:02 AM
Post #7

D.I.C Regular
Group Icon

Joined: 21 Mar, 2008
Posts: 363



Thanked: 19 times
Dream Kudos: 25
My Contributions
QUOTE(3DrunkPandas @ 2 Jul, 2008 - 11:58 AM) *

QUOTE(eclipsed4utoo @ 2 Jul, 2008 - 06:16 AM) *

QUOTE(zakary @ 2 Jul, 2008 - 05:56 AM) *

Maybe 3DrunkPandas forgot that there is no hh in DataTime that hh is used when converting DateTime to string and hh is a string format.


he also forgot that the ".Now" property of the DateTime class is not accessible from an instance of the DateTime class.


Eh sry... I'm currently learning the language, so I'm far from being a professional.


We are here to help others so it's always good to post code that is correct. With you being new to the language(I am also, only about a year and a half under my belt), always do the code in VS before posting it here. Make sure that it does exactly what it should and make sure there are no errors.

User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: How To Get Current Time
2 Jul, 2008 - 11:06 AM
Post #8

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,993



Thanked: 125 times
Dream Kudos: 8625
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Come on now guys, he was merely trying to help, and last time I checked thats what we were here for smile.gif I've inadvertently posted code that had an error (or 2 lol) in it, it happens.
User is offlineProfile CardPM
+Quote Post

zakary
RE: How To Get Current Time
3 Jul, 2008 - 03:19 AM
Post #9

D.I.C Regular
Group Icon

Joined: 15 Feb, 2005
Posts: 405



Thanked: 6 times
Dream Kudos: 175
My Contributions
Oh I know that is why I posted what I did I was not putting him down I was just stating that he may have forgotten I have done that myself once or twice, and I apologies if I offended you 3DrunkPandas, that is not what I was trying to do.

This post has been edited by zakary: 3 Jul, 2008 - 03:24 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 05:39PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month