How to get a timestamp in JavaScript? All methods and examples
Hello everyone! I just started learning JavaScript and encountered a task: I need to get the current timestamp to save to a database and for date comparison. I know that JavaScript has a Date object, but I can't figure out how to properly extract the timestamp.\n\nI tried writing this code:\n\n```javascript\nlet now = new Date();\nconsole.log(now);\n```\n\nBut it outputs something like "Fri Oct 25 2024 14:30:00 GMT+0300", but I need a number — the number of milliseconds or seconds since January 1, 1970. I've seen that some people use `Date.now()`, some use `new Date().getTime()`, and others write `+new Date()`. There's also `Date.parse()` and `valueOf()`. I'm completely confused!\n\nPlease tell me:\n\n1. What is the most correct and modern way to get a timestamp?\n2. What is the difference between
No answers yet.
Log in to leave an answer
Blogs
C# Application Performance Optimization: Best Practices for .NET