轉換時間格式或者想轉換成想要的格式可以使用format

Format(CDate(now), "hh:mm:ss")

參考https://docs.microsoft.com/zh-tw/office/vba/language/reference/user-interface-help/format-function-visual-basic-for-applications

 

語法
Format(Expression, [Format], [FirstDayOfWeek], [FirstWeekOfYear])


Format 函式語法具有以下幾個部分。

部分  描述
運算式    必要。 任何有效運算式。
Format     選用。 有效的具名或使用者定義格式運算式。
FirstDayOfWeek     選用。 常數會指定每週的第一天。
FirstWeekOfYear    選用。 此常數會指定每年的第一週。

 

Format是VB.Net中很好用,不需死記參數,很人性化的格式化Function,舉例:

123456789 (三位一撇千分位)

Format(123456789, "###,###")    OutPut ; 123,456,789

0.2666666 (小數點後兩位,四捨五入,並加上%)

Format(0.2666666,"0.00%")         OutPut  : 26.67%

 千分位,小數點捨去

Format(Val(strValue.ToString), "###,##0")

arrow
arrow

    JL8051 發表在 痞客邦 留言(0) 人氣()