10 examples of 'get date from timestamp javascript' in JavaScript

Every line of 'get date from 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.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
13getTimestamp (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}
3export 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}
90export function timeStampDate(timeStamp) {
91
92 if (typeof timeStamp === "string") {
93 return timeStamp.replace(/T.+/, "");
94 }
95
96 return timeStamp;
97}
31static getDate(timestamp: number): string {
32 return Moment.unix(timestamp).format('DD.MM.YYYY');
33}
45export function getDateFromTimestamp(milliseconds) {
46 return moment.utc(parseInt(milliseconds, 10)).toDate();
47}
78export function toDate(stamp: Time): Date {
79 const { sec, nsec } = stamp;
80 return new Date(sec * 1000 + nsec / 1e6);
81}
520function timeStamp() {
521// Create a date object with the current time
522 var now = new Date();
523
524 var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
525
526// Create an array with the current month, day and time
527 var date = [ months[now.getMonth()], now.getDate() + '-', now.getFullYear() ];
528
529// Create an array with the current hour, minute and second
530 var time = [ now.getHours(), now.getMinutes() ];
531
532// Determine AM or PM suffix based on the hour
533 var suffix = ( time[0] < 12 ) ? "AM" : "PM";
534
535// Convert hour from military time
536 time[0] = ( time[0] < 12 ) ? time[0] : time[0] - 12;
537
538// If hour is 0, set it to 12
539 time[0] = time[0] || 12;
540
541// If seconds and minutes are less than 10, add a zero
542 for ( var i = 1; i < 3; i++ ) {
543 if ( time[i] < 10 ) {
544 time[i] = "0" + time[i];
545 }
546 }
547
548// Return the formatted string
549 return date.join("") + "-" + time.join(".") + "" + suffix;
550}
73function timestamp() {
74 return dateformat('yyyy-mm-dd HH:MM:ss (Z)')
75}
17function timestamp(date) {
18 return Math.floor(new Date(date).getTime() / 1000);
19};
37function getDateString(timestamp: number) {
38 const date = new Date(timestamp);
39 const day = date.getDate();
40 const month_arr = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nove', 'Dec'];
41 const month = month_arr[date.getMonth()];
42 const year = date.getFullYear();
43 const hour = date.getHours();
44 const minutes = date.getMinutes();
45
46 return `${day} ${month} ${year}, ${hour}:${minutes.toString().padStart(2, '0')}`;
47}

Related snippets