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 in c# - string val2;
-
Random ran=new Random();
-
int number=ran.Next(0,1000);
-
val2 = (int) Math.Floor(number);
-
But I dnt which function is used for gettime.
Pls.help me..
Anjana
12 14630
.NET has the DateTime object.
Use DateTime.Now to get the current Date and Time.
But it gives time in different form,I want to actual format of gettime()
But it gives time in different form,I want to actual format of gettime()
use the ToString() method to return your specific format.
cheers
But i dnt knw which format i have to provide in tostring() which is equivalent to
gettime() in javascript.
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.
gettime function of javascript return milliseconds since midnight 1st January, 1970.
Would you tell me for this which format i should used?
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: -
private Int64 GetTime()
-
{
-
Int64 retval=0;
-
DateTime st=DateTime(1970,1,1);
-
TimeSpan t= (DateTime.Now-st);
-
retval= (Int64)(t.TotalMilliseconds+0.5)
-
return retval;
-
}
-
There, did the whole thing for you.
Thanks for this.I'll apply this
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
the corrected one!
UTC should be taken into consideration!! - 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;
-
}
Maybe, but javascript doesn't take UTC into effect.
The idea was to mimic javascript.
Your function could be called:
private Int64 GetUTCTime()
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).
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
by: Steven |
last post by:
Hello,
How to call a C# function (eg., main()) from a Javascript funtion (eg.,
ref()).
-- Steven
|
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...
|
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 (...
|
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...
|
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)
{
|
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 :-(
|
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...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
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...
| |