Skip to content

Commit 2be5e6d

Browse files
committed
Datepicker support for non-US date formats
1 parent 0354d4e commit 2be5e6d

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

docs/example/datepickerDocs.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Selected date is: {{new Date(value).toString().slice(0, -23)}}
2828
<v-option value="yyyy.MM.dd">yyyy.MM.dd</v-option>
2929
<v-option value="MMM/dd/yyyy">MMM/dd/yyyy</v-option>
3030
<v-option value="MMMM/dd/yyyy">MMMM/dd/yyyy</v-option>
31+
<v-option value="dd/MM/yyyy">dd/MM/yyyy</v-option>
32+
<v-option value="dd-MM-yyyy">dd-MM-yyyy</v-option>
3133
</v-select>
3234

3335
<h4>Reset button</h4>
@@ -56,6 +58,8 @@ Selected date is: {{new Date(value).toString().slice(0, -23)}}
5658
<v-option value="yyyy.MM.dd">yyyy.MM.dd</v-option>
5759
<v-option value="MMM/dd/yyyy">MMM/dd/yyyy</v-option>
5860
<v-option value="MMMM/dd/yyyy">MMMM/dd/yyyy</v-option>
61+
<v-option value="dd/MM/yyyy">dd/MM/yyyy</v-option>
62+
<v-option value="dd-MM-yyyy">dd-MM-yyyy</v-option>
5963
</select>
6064
</script></code></pre>
6165
<h2>Option</h2>

src/Datepicker.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ export default {
252252
.replace(/d/g, day)
253253
},
254254
parse(str) {
255+
if (this.format == 'dd-MM-yyyy' || this.format == 'dd/MM/yyyy') {
256+
str = str.substring(3,5)+'-'+str.substring(0,2)+'-'+str.substring(6,10);
257+
}
255258
const date = new Date(str)
256259
return isNaN(date.getFullYear()) ? null : date
257260
},

0 commit comments

Comments
 (0)