Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Need help with javascript date

Need help with javascript date

Need help with javascript date

I have a timestamp object that looks like this: timestamp = 1430770060000. I want to remove the last 3 numbers which represent miliseconds. Since it is a date object, I can't find a method to remove the miliseconds. I tried to convert the value to a string and then use the slice(0,3) to remove the last 3 numbers and convert the remaining 10 characters back to a date, but had an issue. Can someone please help me understand how I can remove the miliseconds from the date.

RE: Need help with javascript date

Have you tried the divide and conquer approach.

Math.floor(timestamp / 100)

Microsoft SQL Server MVP
My Blogs
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom

RE: Need help with javascript date

ahhhhhh, that might do it! Let me try

RE: Need help with javascript date


Quote (George)

Math.floor(timestamp / 100)
Dividing by 100 would move only get rid of the last 2 digits.

Quote (Disskyz)

convert the remaining 10 characters back to a date
As the JavaScript Date objects internally handles dates as milliseconds, you have to use it as is. Rounding it to seconds results a different value so for the Date object a different date.

If is really important for compatibility with other languages' date handling, your best option is to make your own functions to do the handling as you want, maybe as methods of the Date prototype :

CODE --> JavaScript

// declare them
Date.prototype.getUnixTime = function() { return Math.floor(this.getTime() / 1000) }
Date.prototype.setUnixTime = function(time) { return this.setTime(time * 1000) }

// use them
var sometime = new Date()


RE: Need help with javascript date

Have a same problem. Thanks!

https://smurfmania.com/ best site to buy league of legends account

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close