-1

i want convert a datetime variable in ASP.NET MVC to milliseconds,for example like to this:

'1288323623006'

which '1288323623006' in javascript with this format 'yyyy-MM-dd HH:mm:ss Z' means ' 2010-10-29 07:10:23 -3.530'.

WebDeveloper
  • 21
  • 1
  • 1
  • 6

2 Answers2

7

In javascript getTime() return the number of milliseconds since 1970/01/01.

This link is answer for your question DateTime to javascript date

Community
  • 1
  • 1
webdeveloper
  • 17,174
  • 3
  • 48
  • 47
  • this answer is very good, now i have a question:it is possible to convert a datetime to milliseconds which stored to database except now datetime? – WebDeveloper Sep 15 '12 at 12:17
  • If you are taking only about SQL function, you need sothing like [Convert MSSQL Timestamp/Datetime to Unix Timestamp](http://www.adamsdesk.com/be/archives/2011/05/17/how-to-convert-mssql-timestampdatetime-to-unix-timestamp/#axzz26XZC60l2) – webdeveloper Sep 15 '12 at 12:34
  • no,i use entity framework code first and my field type is datetime.now i want fetch datetime which stored in database with Linq To Entity and convert that to milliseconds,now how i can do this? – WebDeveloper Sep 15 '12 at 12:50
  • Use last answer from this question: [DateDiff in LINQ](http://stackoverflow.com/questions/3254417/datediff-in-linq). But you need another method, I didn't have VS now, find function yourself with intellisense. – webdeveloper Sep 15 '12 at 13:21
-1

var d = new Date(your date); then you can apply all the date functions on d this should help. https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date

do you want to convert milliseconds to date or date to milliseconds?

Srinivas
  • 727
  • 4
  • 14
  • date to milliseconds in ASP.NET MVC – WebDeveloper Sep 15 '12 at 07:56
  • Xmas95 = new Date("2010 10 29 07:10:23"); epoch = Xmas95.getTime()/1000; alert(epoch); – Srinivas Sep 15 '12 at 09:26
  • Xmas95 = new Date("2010 10 29 07:10:23"); milli = Xmas95.getMilliseconds(); alert(milli) – Srinivas Sep 15 '12 at 09:26
  • this is incorrect.please read my questions,i said in question and in comment which i want convert date to milliseconds in ASP.NET MVC. Admin,please give Warning to Srinivas Yedhuri. – WebDeveloper Sep 15 '12 at 09:43
  • i saw java-script tag in the question and gave you a java-script answer. i don't think the java-script answer is wrong. its better you edit the title of the question to "convert datetime to milliseconds in ASP.net MVC" to give more clarity. – Srinivas Sep 15 '12 at 10:00