Skip to content

Instantly share code, notes, and snippets.

@ghostflare76
Last active May 10, 2016 04:18
Show Gist options
  • Save ghostflare76/2818547b93bd7b37a022049c7e40e06c to your computer and use it in GitHub Desktop.
Save ghostflare76/2818547b93bd7b37a022049c7e40e06c to your computer and use it in GitHub Desktop.
현재 시간 기준으로 특정 시간대 시간과의 차이 구하기
- 몇 (분/시간/일/월/년)전 표기
한글로 표기시 한글팩 추가 혹은 lang 재정의
Manipulating Dates
var end = moment().subtract('minutes', 40).format();
var time = moment().format();
Relative Time
var result = moment(end).diff(moment(time));
var read = moment.duration(result).humanize(true);
Time from NOW
45초,45분 기준으로 분,시간단위로 변경
Range |Key | Sample Output
========================================================
0 to 45 seconds |s | a few seconds ago
---------------------------------------------------------
45 to 90 seconds | m | a minute ago
--------------------------------------------------------------
90 seconds to 45 minutes | mm | 2 minutes ago ... 45 minutes ago
---------------------------------------------------------------------------
45 to 90 minutes | h | an hour ago
---------------------------------------------------------------------------
90 minutes to 22 hours | hh | 2 hours ago ... 22 hours ago
---------------------------------------------------------------------------
22 to 36 hours | d | a day ago
---------------------------------------------------------------------------
36 hours to 25 days | dd | 2 days ago ... 25 days ago
---------------------------------------------------------------------------
25 to 45 days | M | a month ago
---------------------------------------------------------------------------
45 to 345 days | MM | 2 months ago ... 11 months ago
---------------------------------------------------------------------------
345 to 545 days (1.5 years) |y | a year ago
---------------------------------------------------------------------------
546 days+ |yy | 2 years ago ... 20 years ago
---------------------------------------------------------------------------
https://jsfiddle.net/7mhk6q57/4/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment