×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*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.

# Need help with javascript date

## Need help with javascript date

(OP)
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)

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

### RE: Need help with javascript date

(OP)
ahhhhhh, that might do it! Let me try

### RE: Need help with javascript date

Hi

#### 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()
sometime.setUnixTime()
console.log(sometime.getUnixTime()) 

Feherke.
feherke.github.io

### 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.

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:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!