Skip to content

Commit 6fe42ed

Browse files
committed
Added methods to set/get local and UTC dates
1 parent 8170086 commit 6fe42ed

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/js/bootstrap-datetimepicker.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,25 @@
160160
this.fillDate();
161161
this.fillTime();
162162
},
163+
164+
getDate: function() {
165+
return new Date(this.date.valueOf());
166+
},
167+
168+
setDate: function(date) {
169+
this.setValue(date.valueOf());
170+
},
171+
172+
getLocalDate: function() {
173+
var d = this.date;
174+
return new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(),
175+
d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds());
176+
},
177+
178+
setLocalDate: function(localDate) {
179+
this.setValue(Date.UTC(localDate.getFullYear(), localDate.getMonth(), localDate.getDate(),
180+
localDate.getHours(), localDate.getMinutes(), localDate.getSeconds(), localDate.getMilliseconds()));
181+
},
163182

164183
place: function(){
165184
var offset = this.component ? this.component.offset() : this.$element.offset();

0 commit comments

Comments
 (0)