Skip to content

Instantly share code, notes, and snippets.

@thomasjao
Created January 29, 2015 14:36
Show Gist options
  • Save thomasjao/81788818b23af67f0754 to your computer and use it in GitHub Desktop.
Save thomasjao/81788818b23af67f0754 to your computer and use it in GitHub Desktop.
Convert epoch of Taiwan to AD
/* Epoch used in Taiwan started since 1911 AD. For example, this year (2015 AD) in Taiwan epoch is 中華民國 104 年
Often we need to different epoch notation between system/languages */
/* From String to JavaScript
Taiwan epoch notation -- '104.01.29'
AD -- Thu Jan 29 2015 22:27:19 GMT+0800 (CST) */
var str2JSdate = function( str ) {
var dt = new Date();
var date_arr = str.split('.');
dt.setFullYear( parseInt( date_arr[0] ) + 1911 );
dt.setMonth( parseInt( date_arr[1] ) - 1 );
dt.setDate( date_arr[2] );
return dt;
}
/* Usage, provide string 'yyy.mm.dd' as function parameter */
var date_string = '104.01.29';
console.log( str2JSdate( date_string ));
/* return Thu Jan 29 2015 22:35:27 GMT+0800 (CST) */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment