Skip to content

Instantly share code, notes, and snippets.

@bellx2
Created December 1, 2019 03:51
Show Gist options
  • Save bellx2/fd35db4801284453304155d7e7653aa4 to your computer and use it in GitHub Desktop.
Save bellx2/fd35db4801284453304155d7e7653aa4 to your computer and use it in GitHub Desktop.
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment-with-locales.js"></script>
<div id="app">
<input v-model="mytime">
<p>
<p>FromNow : {{ time_diff() }}
<p>Diff(sec) : {{ time_diff_sec() }}
</div>
<script>
var app = new Vue({
el: '#app',
data: {
mytime: moment().format("YYYY/MM/DD HH:mm:ss"),
},
methods: {
time_diff: function(){
moment.locale('ja')
return moment(this.mytime).fromNow()
},
time_diff_sec: function(){
return moment(this.mytime).diff(moment(),'seconds')
}
}
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment