Advertisement
mahmudkuet

Local Date

Jul 30th, 2019
552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <template>
  2.     <span>{{ localDate }}</span>
  3. </template>
  4.  
  5. <script>
  6.     import moment from 'moment-timezone';
  7.  
  8.     export default {
  9.         props: ['date', 'input_format', 'output_format'],
  10.         data(){
  11.             return {
  12.                 format: {
  13.                     input: 'YYYY-MM-DD HH:mm:ss',
  14.                     output: 'MMM DD, YYYY h:mm:ss A'
  15.                 }
  16.             };
  17.         },
  18.         mounted(){
  19.             if(this.input_format){
  20.                 this.format.input = this.input_format;
  21.             }
  22.             if(this.output_format){
  23.                 this.format.output = this.output_format;
  24.             }
  25.         },
  26.         computed: {
  27.             localDate(){
  28.                 return moment.tz(this.date, this.format.input, 'UTC').tz(moment.tz.guess()).format(this.format.output);
  29.             }
  30.         }
  31.     }
  32. </script>
  33.  
  34. <style scoped="">
  35.  
  36. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement