473,320 Members | 1,900 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,320 software developers and data experts.

c# function equivalent to javascript gettime function

6
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
Expand|Select|Wrap|Line Numbers
  1. //javascript
  2. var unique = d.getTime() + '' + Math.floor(1000 * Math.random());

I used following code in c#

Expand|Select|Wrap|Line Numbers
  1. string val2;
  2. Random ran=new Random();
  3. int number=ran.Next(0,1000);
  4. val2 = (int) Math.Floor(number);
  5.  
But I dnt which function is used for gettime.


Pls.help me..


Anjana
Sep 25 '07 #1
12 14630
Plater
7,872 Expert 4TB
.NET has the DateTime object.
Use DateTime.Now to get the current Date and Time.
Sep 25 '07 #2
anj2k5
6
But it gives time in different form,I want to actual format of gettime()
Sep 26 '07 #3
Shashi Sadasivan
1,435 Expert 1GB
But it gives time in different form,I want to actual format of gettime()
use the ToString() method to return your specific format.
cheers
Sep 26 '07 #4
anj2k5
6
But i dnt knw which format i have to provide in tostring() which is equivalent to
gettime() in javascript.
Sep 26 '07 #5
Plater
7,872 Expert 4TB
But i dnt knw which format i have to provide in tostring() which is equivalent to
gettime() in javascript.
Well how about LOOKING at it, and deciding.
OR look up to see what format gettime() in javascript returns as and then you can force the DateTime object to output in that format.

Time to do some of your own leg work there.
Sep 26 '07 #6
anj2k5
6
gettime function of javascript return milliseconds since midnight 1st January, 1970.
Would you tell me for this which format i should used?
Sep 26 '07 #7
Plater
7,872 Expert 4TB
gettime function of javascript return milliseconds since midnight 1st January, 1970.
Would you tell me for this which format i should used?
Well to ensure it:

Expand|Select|Wrap|Line Numbers
  1. private Int64 GetTime()
  2. {
  3.    Int64 retval=0;
  4.    DateTime st=DateTime(1970,1,1);
  5.    TimeSpan t= (DateTime.Now-st);
  6.    retval= (Int64)(t.TotalMilliseconds+0.5)
  7.    return retval;
  8. }
  9.  
There, did the whole thing for you.
Sep 26 '07 #8
anj2k5
6
Thanks for this.I'll apply this
Oct 5 '07 #9
Thanks for writing up this description. I'm not sure that the original poster had a full appreciation for your comments and support but I do - it saved me a great amount of time. Problem solved!

@Plater
Jan 21 '09 #10
MCBoy
3
the corrected one!

UTC should be taken into consideration!!

Expand|Select|Wrap|Line Numbers
  1. private Int64 GetTime()
  2. {
  3.    Int64 retval=0;
  4.    DateTime st=DateTime(1970,1,1);
  5.    TimeSpan t= (DateTime.Now.ToUniversalTime()-st);
  6.    retval= (Int64)(t.TotalMilliseconds+0.5)
  7.    return retval;
  8. }
Feb 21 '10 #11
Plater
7,872 Expert 4TB
Maybe, but javascript doesn't take UTC into effect.
The idea was to mimic javascript.
Your function could be called:
private Int64 GetUTCTime()
Feb 22 '10 #12
MCBoy
3
by default javascript date object is UTC. All dates are calculated in milliseconds from 01 January, 1970 00:00:00 Universal Time (UTC) with a day containing 86,400,000 milliseconds.

refer: http://www.w3schools.com/js/js_obj_date.asp (W3Schools, JavaScript Date Object).
Jul 16 '10 #13

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

Similar topics

5
by: Bartosz Wegrzyn | last post by:
Any ideas why this function is not working. I am running it locally on my private network. <!doctype html public "-//w3c//dtd html 4.0 transitional//en"> <html> <head> <title>Javascript...
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...
4
by: Steven | last post by:
Hello, How to call a C# function (eg., main()) from a Javascript funtion (eg., ref()). -- Steven
3
by: Steve | last post by:
Is there equivalent of sscanf function in .NET? I need to parse string with network MAC address (For example like 11-22-33-44-55-66) and extract each segment into array of bytes. Can anyone...
2
by: ljlolel | last post by:
I'm posting this again because I did not explain myself well the first time, so the problem was not being addressed. I made the following page (...
0
by: Boricua | last post by:
I'm using ASP.NET 2.0 I got an imagebutton at the end of my form as a submit button. When the user clicks it the button becomes disabled and continues with the postback. This is what I got, ib...
28
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
2
by: Adam Kubica | last post by:
Hellou. Anybody know about code that work equivalent to gzinflate() function used in PHP? I search via google but I don't found anything sensible :-(
4
by: Waldy | last post by:
Hi there, I have a customer requirement to provide a web application without JavaScript. A function is being written to the HTML output on some pages. The function is called __doPostBack. How...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.