473,583 Members | 2,875 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getTime() method in C#

270 Contributor
Hi, i'm newbie in C#, Consider following function in java:
Expand|Select|Wrap|Line Numbers
  1. int getMilliseconds(){ Date dt=new Date(); return(dt.getTime()); }
pls help me to convert this in C#
May 17 '08 #1
7 34505
NitinSawant
270 Contributor
reply Fast, I'm waiting for the reply
May 17 '08 #2
Shashi Sadasivan
1,435 Recognized Expert Top Contributor
DateTime.Now.Mi llisecond;

Millisecond is a property of the datetime class.
It wil return the current state of the millisecond part of the time.

Is tat what you are looking for?
May 17 '08 #3
NitinSawant
270 Contributor
No, not in that way,
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <button onclick="var myDate = new Date(); alert(myDate.getTime());">
  4. get time
  5. </button>
  6. </body>
  7. </html>
  8.  
i just want to convert the line
"var myDate = new Date(); alert(myDate.ge tTime());" into C#
May 17 '08 #4
Curtis Rutland
3,256 Recognized Expert Specialist
No, not in that way,
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <button onclick="var myDate = new Date(); alert(myDate.getTime());">
  4. get time
  5. </button>
  6. </body>
  7. </html>
  8.  
i just want to convert the line
"var myDate = new Date(); alert(myDate.ge tTime());" into C#
If you want the current date and time, use
Expand|Select|Wrap|Line Numbers
  1. DateTime myDate = DateTime.Now;
  2.  
Now myDate has the current date and time. That object has all the members and methods you need to convert that time to any format or break out any part of it you need.

If this is a Windows Forms application, the next part would be:
Expand|Select|Wrap|Line Numbers
  1. MessageBox.Show(myDate.ToShortTimeString());
  2.  
If this is an ASP.NET web app, I don't think that there is any way to create a client-side pop up from C#.
May 17 '08 #5
NitinSawant
270 Contributor
If you want the current date and time, use
Expand|Select|Wrap|Line Numbers
  1. DateTime myDate = DateTime.Now;
  2.  
Now myDate has the current date and time. That object has all the members and methods you need to convert that time to any format or break out any part of it you need.

If this is a Windows Forms application, the next part would be:
Expand|Select|Wrap|Line Numbers
  1. MessageBox.Show(myDate.ToShortTimeString());
  2.  
If this is an ASP.NET web app, I don't think that there is any way to create a client-side pop up from C#.
Gr8, thanx for relplying
May 18 '08 #6
Shashi Sadasivan
1,435 Recognized Expert Top Contributor
Just to inform you. Your code was javascript and not java !
May 19 '08 #7
MCBoy
3 New Member
if you are using a system, where the current time is not in UTC, then this will not work. javascript getTime gets the diff with UTC.

# private Int64 GetTime()
# {
# Int64 retval=0;
# DateTime st=DateTime(197 0,1,1);
# TimeSpan t= (DateTime.Now.T oUniversalTime( )-st);
# retval= (Int64)(t.Total Milliseconds+0. 5)
# return retval;
# }
Feb 21 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
11641
by: Phil Powell | last post by:
I am forced to have to compare the value of some PHP timestamp with a Java-based java.util.Date.getTime() timestamp. Let me show you how they look: The Java time is returned to the PHP class method as mixed but could be converted to float I would think, but how would I ensure that they
11
3609
by: Dave Rahardja | last post by:
OK, so I've gotten into a philosophical disagreement with my colleague at work. He is a proponent of the Template Method pattern, i.e.: class foo { public: void bar() { do_bar(); } protected: virtual void do_bar() {} };
5
15352
by: Chris | last post by:
Hi I have a scenario where I've created another AppDomain to dynamically load a DLL(s) into. In this newly loaded DLL I want to call a static method on a class. The problem arise is that I have the same class/static method definition statictly linked to my EXE and when I call InvokeMember(...), even though I got the Type from the new AppDomain,...
1
2228
by: Shane | last post by:
I have this peice of Javascript, im trying to convert in to VB.net. Everything work ok. I almost get the some value, but the last 5 numbers are all Zeros on my VB out put. the Java version has numbers there and makes the out a little different. I want to know if there is a better why in VB i can do this I am taking the difference of two dates...
3
1476
by: Xiangliang Meng | last post by:
Hi, all class Clock { Clock() { Time_m = 0;} void setTime(unsigned int time = 0) { Time_m = time; } unsigned int getTime() const
4
2895
by: daniel.w.gelder | last post by:
I wrote a template class that takes a function prototype and lets you store and call a C-level function, like this: inline string SampleFunction(int, bool) {..} functor<string (int, bool)> myFunctor = SampleFunction; string result = myFunctor(7, true); Works great thanks to the help from this group. Here's the guts so far for two-arity:
8
6103
by: Russ Chinoy | last post by:
Has anyone ever noticed that getTime() returns the same value for both today (5/31/2005) and tomorrow (6/1/2005)? You can quickly see it with this page: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> <script>
2
7294
by: Shane Saunders | last post by:
I trying to make a sub that works like Javascripts .getTime method. It work ok, but it does not should the time in it. The last numbers should be the time, but they are all zeros. Can anyone help me on this. here is the code i used. From reading i also seen that the getTime time starts on 01/01/1970 12am. I need to have this in Millsecond. ...
12
14707
by: anj2k5 | last post by:
Hello , I want to create a function in C#.net which is equivalent to gettime(milliseconds since midnight 1st January, 1970 ) function in javascript. Actually i need to calculate unique value in c#.net as given in following javascript //javascript var unique = d.getTime() + '' + Math.floor(1000 * Math.random()); I used following code...
0
7896
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8186
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8329
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8197
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6583
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3847
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2335
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1436
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1160
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.