Ad
ReferenceError: Timestamp Is Not Defined
I am trying to convert Firebase TimeStamp
into JavaScript date.
I referred this link to convert Javascript object to Javascript date, https://firebase.google.com/docs/reference/js/firebase.firestore.Timestamp
Firestore timestamp (From API):
"time": {
"_seconds": 1563620755,
"_nanoseconds": 688000000
}
Before saving time
into cloud firestore I've to convert it to JavaScript Date()
.
So I used below code to convert object into Date.
let data = request.body
let tiemStamp = new Timestamp(data.time._seconds,data.time._nanoseconds)
But I got below error,
ReferenceError: Timestamp is not defined
How do to solve it? Thanks!
Ad
Answer
As Timestamp
is under firebase.firestore
namespace (or in Javascripts case object), you might want to use it as follows:
let tiemStamp = new firebase.firestore.Timestamp(data.time._seconds,data.time._nanoseconds)
console.log(new firebase.firestore.Timestamp());
<script src="https://www.gstatic.com/firebasejs/6.3.5/firebase.js"></script>
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad