以正确的格式打印日期 [英] Print dates in proper format

查看:68
本文介绍了以正确的格式打印日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一本有很多日期的excel工作簿。

I have an excel workbook with many dates.


  • 在工作表上,它们的格式为 mm / dd / yy hh :mm

  • 我在工作表上方白框中看到的格式为 dd / mm / yy hh:mm

我需要将工作表打印到文本文件中,但是当我这样做时,它的打印格式为 dd / mm / yy hh:mm ,而不是 mm / dd / yy hh:mm

I need to print the worksheets into text files, but when I do so, it's printing in the format of dd/mm/yy hh:mm, Instead of mm/dd/yy hh:mm.

这是代码:

         For i = 1 To LastRow
            For j = 1 To LastCol
                If j = LastCol Then
                    DataLine = DataLine + Trim(Cells(i, j).Value)
                Else
                    DataLine = DataLine + Trim(Cells(i, j).Value) + vbTab
                End If
            Next j

            If (DataLine <> "") Then
                Print #FileNum, DataLine
                DataLine = ""
            End If
        Next i

是否有人知道如何以我需要的格式打印表格?

Does any one has an idea how to print the sheets in the format I need?

推荐答案

您可以使用 Format 函数来自定义日期的文本格式。

You can use the Format function to customize the text formatting of dates.

我转义了正斜杠 / ,因为否则它将被解释为日期分隔符,而实际字符用作日期格式化输出中的分隔符取决于系统设置(来自文档)。使用转义符时,它应该始终输出 / 字符。

I escaped the forward slash / because otherwise it is interpreted as the date separator and "The actual character used as the date separator in formatted output is determined by your system settings" (from documentation). With escaping, it should always output a / character.

Format(Cells(1, 1).Value, "MM\/dd\/yy hh:mm")

这篇关于以正确的格式打印日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆