Table of contents
No headings in the article.
Hello everyone! Here is the story of two colleagues who were perplexed and confused while they implement some functionalities.Both are interested in lending hands with themselves whenever they are bewildered. One is Veera and the other is Deepi. Their conversation started like below.
Deepi: Oops! My code is not working properly. Please help on this since i was implementing it for a longer time.
Veera: Yes Deepi we will sit together and resolve this. Let me know the problem statement briefly.
Deepi: I want to convert one particular date which is in UTC to timestamp. And also i am puzzled about that UTC
Veera: Okay ! Let me brief you about UTC.UTC is the time standard commonly used across the world. The world's timing centres have agreed to keep their time scales closely synchronised - or coordinated - therefore the name Coordinated Universal Time.
Deepi: Oh Good to know new information. Please proceed.
Veera: Before getting into solution, you should know about MomentJS.
Deepi: I am aware of some javascript packages, but what is this?
Veera: MomentJS is a JavaScript library which helps in parsing, validating, manipulating and displaying date/time in JavaScript in a very easy way.Moment JS allows displaying of date as per localization and in human readable format. You can use MomentJS inside a browser using the script method. It is also available with Node.js and can be installed using npm.
Deepi: Thats pretty interesting. Please go ahead.
Veera: In MomentJS, you can find many easy methods to add, subtract, validate date, get the maximum, minimum date etc. It is an open source project and you can easily contribute to the library and add features in the form of plugins and make it available on GitHub and in Node.js.
Deepi: Awesome. So what are the prerequisite to use MomentJS?
Veera: First make sure you have Node.js and npm installed on your system. You can use the following command to install MomentJS
npm install moment
Deepi: Cool! I installed it.
Veera: Now you have to import moment in the file which you use. Copy the below snippet.
const moment = require('Moment');
Deepi: Done this too. I am eager in finding the solution to my problem.
Veera: Yes , here it is. You can use the below code to convert current date and time to timestamp.
var timestamp= moment().utc().unix();
Deepi: Its working great but i need to know how to convert some particular date and time to timestamp. The same code works?
Veera: In that case, please look the below code.
var date = moment.utc(convert_date).unix();
Deepi: Cool! Its working fine. Thanks a lot Veera. Learnt cool information today and below are the results...
Veera: Good to know that you understood. Happy Coding Happy Learning.
Community and Social Footprints :