I’m trying to convert UTC time to the local time. I’ve been following this example from this link: http://jsfiddle.net/FLhpq/4/light/. I can’t seem to get the right local output. For example, if its 10: 30 am in here, instead of getting 10:30 ill get 15: 30. Here is my code:
var date = moment.utc().format('YYYY-MM-DD HH:mm:ss'); var localTime = moment.utc(date).toDate(); localTime = moment(localTime).format('YYYY-MM-DD HH:mm:ss'); console.log("moment: " + localTime);
No matter what I do the time always comes out at UTC time. I live in Houston so I know timezone is the issue. I’ve followed the code in the link but can seem to get the local time. What am I doing wrong?
Related Posts:
- Get hours difference between two dates in Moment Js
- How to format a JavaScript date
- How to format a JavaScript date
- How do I get the current date in JavaScript?
- Get String in YYYYMMDD format from JS date object?
- Compare two dates with JavaScript
- Compare dates with javascript
- Add days to JavaScript Date
- Parsing a string to a date in JavaScript
- Format JavaScript date as yyyy-mm-dd
- Add days to JavaScript Date
- Moment js date time comparison
- How to validate date with format “mm/dd/yyyy” in JavaScript?
- How to subtract date/time in JavaScript?
- Getting current date and time in JavaScript
- Shortest way to print current year in a website
- Moment.js transform to date object
- Validate date in dd/mm/yyyy format using JQuery Validate
- How to subtract days from a plain Date?
- How to add 30 minutes to a JavaScript Date object?
- How do you convert a JavaScript date to UTC?
- Convert UTC Epoch to local date
- Convert normal date to unix timestamp
- Check time difference in Javascript
- How to convert date to timestamp?
- How to format a UTC date as a `YYYY-MM-DD hh:mm:ss` string using NodeJS?
- momentJS date string add 5 days
- Javascript: getFullyear() is not a function
- Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’
- Cross-Origin Read Blocking (CORB)
- How can I remove a specific item from an array?
- How to use Redirect in the new react-router-dom of Reactjs
- How to fix “Cannot read property ‘addEventListener’ of null” error [duplicate]
- What does [object Object] mean?
- Remove class using jQuery
- How do I check whether a checkbox is checked in jQuery?
- Babel 7 – ReferenceError: regeneratorRuntime is not defined
- How can I refresh a page with jQuery?
- How can I create a two dimensional array in JavaScript?
- Does JavaScript pass by reference?
- How to add jQuery code into HTML Page
- Get the current year in JavaScript
- Pure JavaScript: a function like jQuery’s isNumeric()
- jquery SlideToggle effect in upward direction?
- Deleting array elements in JavaScript – delete vs splice
- How can I determine if a variable is ‘undefined’ or ‘null’?
- Cannot find module ‘@angular-devkit/core’
- iFrame onload JavaScript event
- Node.js Error: connect ECONNREFUSED
- How to move an element into another element?
- Is there an arraylist in Javascript?
- How to convert JSON object to JavaScript array?
- How to move all HTML element children to another parent using JavaScript?
- How to print HTML content on click of a button, but not the page?
- explode string in jquery
- JavaScript – cannot set property of undefined
- Why is this jQuery click function not working?
- Simple average function in Javascript
- How to uncheck a radio button?
- How can I extract a number from a string in JavaScript?
- Angularjs: Error: [ng:areq] Argument ‘HomeController’ is not a function, got undefined
- Truncate a string straight JavaScript
- Force div to be topmost element of any and all webpages
- moving an element in JS
- Is there a way to get element by XPath using JavaScript in Selenium WebDriver?
- Get class list for element with jQuery
- Print a div content using Jquery
- Get the size of the screen, current web page and browser window
- How to reload/refresh jQuery dataTable?
- How to enable a disabled checkbox dynamically?
- “Cross origin requests are only supported for HTTP.” error when loading a local file
- How to use aria-expanded=”true” to change a css property
- How do I concatenate a string with a variable?
- setTimeout callback argument
- Nonce retrieved from the REST API is invalid and different from nonce generated in wp_localize_script
- Gutenberg – remove / add blocks with custom script
- conditional layout based on if Innerblocks is not empty
- Only loads on the contact template page
- Min And Max Date With Date Format In Elementor Form Not Working
- Strange gibberish JavaScript in Editor – site hacked?
- Building a slide down search box in wordpress
- javascript conflict
- esc_js() breaks unicode sequences by removing the slash ‘\’ character
- How to load JS for specific screen size using wp_enqueue_script?
- Video script issue, JavaScript attribute remains ‘undefined’
- Why does a on Comment edit page submit the page?
- Where to paste Google Map Snippet / JavaScript / CSS for WordPress integration
- Custom JS text area in customizer is being formatted wrong in document
- TinyMCE Javascript URL Question
- Setting Variable Path to Template Directory inside Script
- Dynamically add Js
- how to prevent added meta box from being injected with style=”position: fixed; top: 56px;” at scroll down
- Contact Form 7 Conditional redirect
- How do i load javascript on a specific custom post template via functions.php?
- How to use value from modal tinymce windowManager?
- Can’t change javascript files
- Wysiwyg editor not working on 4.2.2
- Live Time on WP showing weirdly [closed]
- Google Map JavaScript error after migrating
- Uncaught SyntaxError: missing ) after argument list [duplicate]