vb .net 2012 datepicker大写的MAY月份变为5AY

时间:2018-08-29 03:06:32

标签: vb.net

我使用此代码以大写形式表示月份,问题在于5月变成5AY

DateTimePicker1.Format = DateTimePickerFormat.Custom
DateTimePicker1.CustomFormat = Strings.UCase(Format(DateTimePicker1.Value, "ddMMMyyyy"))

enter image description here

1 个答案:

答案 0 :(得分:0)

在意识到您试图在格式说明符中实际使用月份名称作为原义字符后,我知道您只需要转义那些特殊字符。通常,日期格式说明符使用“ \”字符进行转义,但是const toggleShowUsers = () => { return dispatch => { // [UPDATE] // Once the toggle is complete, do fetch // request. Not sure how you plan to aquire // the id, so am substituting value 1 here fetchUser(1)(dispatch).then(() => { // [UPDATE] // In promise handler, dispatch ShowUsers // when fetchUser has completed dispatch({ type: Constants.ShowUsers, }); }); } } const fetchUser = (userId) => { return dispatch => { let url = .... // [UPDATE] // Return promise from axios.get return axios.get(url) .then(function(resp) { dispatch({ type: Constants.fetchUser, users: resp.data.users, }); }); }; } export default { toggleShowUsers, fetchUser } 属性特别要求您将转义的字符用单引号引起来。我刚刚测试了一下,它按预期工作了:

DateTimePicker.CustomFormat

如果您使用的VB较旧版本不支持字符串插值,则将执行相同的操作:

Private Sub DateTimePicker1_ValueChanged(sender As Object, e As EventArgs) Handles DateTimePicker1.ValueChanged
    DateTimePicker1.CustomFormat = $"dd'{DateTimePicker1.Value.ToString("MMM").ToUpper()}'yyyy"
End Sub

由于代码不会更改,因此无需在代码中设置Private Sub DateTimePicker1_ValueChanged(sender As Object, e As EventArgs) Handles DateTimePicker1.ValueChanged DateTimePicker1.CustomFormat = String.Format("dd'{0}'yyyy", DateTimePicker1.Value.ToString("MMM").ToUpper()) End Sub 属性。只需在设计器中设置一次即可。您可能想要在Format上执行相同的代码,因为默认情况下,Load的当前日期/时间没有ValueChanged事件。