473,385 Members | 1,531 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

getTime() method in C#

270 100+
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 34435
NitinSawant
270 100+
reply Fast, I'm waiting for the reply
May 17 '08 #2
Shashi Sadasivan
1,435 Expert 1GB
DateTime.Now.Millisecond;

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 100+
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.getTime());" into C#
May 17 '08 #4
Curtis Rutland
3,256 Expert 2GB
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.getTime());" 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 100+
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 Expert 1GB
Just to inform you. Your code was javascript and not java !
May 19 '08 #7
MCBoy
3
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(1970,1,1);
# TimeSpan t= (DateTime.Now.ToUniversalTime()-st);
# retval= (Int64)(t.TotalMilliseconds+0.5)
# return retval;
# }
Feb 21 '10 #8

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

Similar topics

2
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...
11
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:...
5
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...
1
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...
3
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
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)>...
8
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...
2
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...
12
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.