Last active
April 7, 2016 06:08
-
-
Save ocristian/085768fecae7a618b41db2e558153445 to your computer and use it in GitHub Desktop.
to find the current local date and time based on user system
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Example: 4/7/2016 3:00 AM BRT | |
| function currentLocalDateTime(){ | |
| var date = new Date(); | |
| var curr_year = date.getFullYear(); | |
| var curr_month = ("00" + (date.getMonth() + 1)).slice(-2); | |
| var curr_dayOfMonth = ("00" + date.getDate()).slice(-2); | |
| var curr_hour = date.getHours(); | |
| var curr_minute = ("00" + date.getMinutes()).slice(2); | |
| var am_pm = curr_hour > 12 ? 'PM' : 'AM'; | |
| var dateString = date.toString().split(" "); | |
| var time_zone_abbr = dateString.pop().replace(/[^a-zA-Z]/g, ''); | |
| var current_local_time = curr_month.concat('/').concat(curr_dayOfMonth).concat('/').concat(curr_year).concat(' ').concat(curr_hour).concat(':').concat(curr_minute).concat(' ').concat(am_pm).concat(' ').concat(time_zone_abbr); | |
| console.log('Current local time: ' + current_local_time); | |
| return current_local_time; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very nice with MomentJS :)
First, import the dependencies:
and them: