 |
MDN date |
On a React Native app, we can use JS Date object to get day and current time.
With that, you can display the right greetings, style our app's components, present different view components etc. You can then use
switch statements to achieve this.
let present = new Date();
present.getDay(); // return 0: Sunday - 6: Saturday
present.getHours();
You can also use it to set your copyright year at the footer of your website like so using React:
setCopyrightLine() {
let present = new Date();
let year = present.getFullYear();
this.setState({
copyrightLine: `Made by Jun Goh - \u{00A9} ${year}`
})
}
References:
MDN Date,
JavaScript Blog
Thank you for reading!
Jun
Comments
Post a Comment