Every line of 'convert date to timestamp javascript' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
3 export function timestampToDate(timestamp?: pb.google.protobuf.ITimestamp) { 4 let millis: number 5 if (!timestamp) { 6 millis = 0 7 } else { 8 millis = timestamp.seconds as number * 1e3 + timestamp.nanos / 1e6 9 } 10 return new Date(millis) 11 }
90 export function timeStampDate(timeStamp) { 91 92 if (typeof timeStamp === "string") { 93 return timeStamp.replace(/T.+/, ""); 94 } 95 96 return timeStamp; 97 }
13 getTimestamp (date) { 14 return new Date( 15 date.getFullYear(), 16 date.getMonth(), 17 date.getDate(), 18 this.time.hour, 19 this.time.min, 20 0, 0) 21 }
78 export function toDate(stamp: Time): Date { 79 const { sec, nsec } = stamp; 80 return new Date(sec * 1000 + nsec / 1e6); 81 }
66 function dateConverter(timestamp, format) { 67 68 //JS uses nanoseconds, hence the *100 multiplication 69 var a = new Date(timestamp * 1000); 70 71 //short names of all twelve months 72 var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; 73 74 //thee variables used for getting timestamp time 75 var hrs = a.getHours(), 76 min = a.getMinutes(), 77 sec = a.getSeconds(); 78 79 //improving readability: adding leading zero 80 if (hrs === 0) { 81 hrs = "0" + hrs; 82 } 83 if (min < 10) { 84 min = "0" + min; 85 } 86 if (sec < 10) { 87 sec = "0" + sec; 88 } 89 90 if (!format) { 91 //returns in format 'd M Y, H:i:s' 92 return a.getDate() + ' ' + 93 months[a.getMonth()] + ' ' + 94 a.getFullYear() + ', ' + 95 hrs + ':' + min + ':' + sec; 96 97 } else if (format === "time") { 98 return hrs + ':' + min + ':' + sec; 99 } 100 101 }
200 public toJavaScriptDate(implicitTimezone = undefined): Date { 201 const timezoneToUse = 202 this._timezone || implicitTimezone || DayTimeDuration.fromTimezoneString('Z'); 203 return new Date( 204 Date.UTC( 205 this._years, 206 this._months - 1, 207 this._days, 208 this._hours - timezoneToUse.getHours(), 209 this._minutes - timezoneToUse.getMinutes(), 210 this._seconds + this.secondFraction 211 ) 212 ); 213 }
45 export function getDateFromTimestamp(milliseconds) { 46 return moment.utc(parseInt(milliseconds, 10)).toDate(); 47 }
12 toJsDate() { 13 return new Date(this._value.getTime()); // return a clone. 14 }
31 static getDate(timestamp: number): string { 32 return Moment.unix(timestamp).format('DD.MM.YYYY'); 33 }
95 export function solrTimestamp(date) { 96 return moment(date).format('x'); 97 }