Skip to content

Add function toTimeZone #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions dist/jquery-dateFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var DateFormat = {};
'Jul': '07', 'Aug': '08', 'Sep': '09', 'Oct': '10', 'Nov': '11', 'Dec': '12' };

var YYYYMMDD_MATCHER = /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.?\d{0,3}[Z\-+]?(\d{2}:?\d{2})?/;
var EN_US_FORMAT_MATCHER = /\d{1,2}\/\d{1,2}\/\d{4},??\s\d{1,2}:\d{1,2}:\d{1,2}/;

$.format = (function() {
function numberToLongDay(value) {
Expand Down Expand Up @@ -132,6 +133,14 @@ var DateFormat = {};
parsedDate.month = values[1];
parsedDate.dayOfMonth = values[2];
parsedDate.time = parseTime(values[3].split('.')[0]);
} else if(value.search(EN_US_FORMAT_MATCHER) != -1) {
/* 10/1/2017, 0:00:00 || 10/1/2017 0:00:00 */
value = value.replace(',', '');
values = value.split(/[\s\/]/);
parsedDate.year = values[2];
parsedDate.month = values[0];
parsedDate.dayOfMonth = values[1];
parsedDate.time = parseTime(values[3]);
} else {
values = value.split(' ');
if(values.length === 6 && isNaN(values[5])) {
Expand Down Expand Up @@ -463,6 +472,12 @@ var DateFormat = {};
},
toBrowserTimeZone : function(value, format) {
return this.date(new Date(value), format || 'MM/dd/yyyy HH:mm:ss');
},
toTimeZone : function (value, timeZone, format){
// timeZone : Asia/Tokyo etc..
// clear LRM in IE
var date = new Date(value).toLocaleString('en-US', {timeZone: timeZone, hour12: false}).replace(/‎|\u200E/gi, '');
return this.date(new Date(date), format || 'MM/dd/yyyy HH:mm:ss');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nev-tuannm4 could you move the change to https://github.com/phstc/jquery-dateFormat/blob/master/src/dateFormat.js, this dist/jquery-dateFormat.js is the compiled file.

}
};
}());
Expand Down