473,657 Members | 2,463 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

c# function equivalent to javascript gettime function

6 New Member
Hello ,

I want to create a function in C#.net which is equivalent to gettime(millise conds 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 14720
Plater
7,872 Recognized Expert Expert
.NET has the DateTime object.
Use DateTime.Now to get the current Date and Time.
Sep 25 '07 #2
anj2k5
6 New Member
But it gives time in different form,I want to actual format of gettime()
Sep 26 '07 #3
Shashi Sadasivan
1,435 Recognized Expert Top Contributor
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 New Member
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 Recognized Expert Expert
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 New Member
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 Recognized Expert Expert
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 New Member
Thanks for this.I'll apply this
Oct 5 '07 #9
paotech
1 New Member
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

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

Similar topics

5
1857
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 Webcam for Internet Explorer</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
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 and making them in to a long intger. here is the code for both and the out put VB.net Code Dim...
4
35980
by: Steven | last post by:
Hello, How to call a C# function (eg., main()) from a Javascript funtion (eg., ref()). -- Steven
3
1990
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 advise what method/class I can use for that? I've figured out how to parse IP address: IPAddress.Parse(hostName), but can't find easy way to parse MAC address.
2
2231
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 ( http://perla.princeton.edu/counselors/organization.php ) solely for the purpose of showing a bug. It is not production code, it is a test, made for testing, so style really doesn't matter. This page illustrates that, for some reason, clicking on the submit button has a different effect on the...
0
2679
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 is the imagebutton. Dim sbValid As New StringBuilder() sbValid.Append("if(typeof(Page_ClientValidate)=='function'){ ") sbValid.Append("if (Page_ClientValidate() == false) { return false; }} ")
28
4307
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
4018
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
5702
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 do I get rid of it. There is no call to the function in the rest of the page, so why is it being written to the client?
0
8411
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8323
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8838
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8513
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7351
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.