热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何在Excel中显示hh:mm:ss?-Howtodisplayhh:mm:ssinExcel?

ImnewtoExcelVBA.Iwanttosetupaloopthatwilldisplaythetimeforeachminuteontheminu

I'm new to Excel VBA. I want to set up a loop that will display the time for each minute on the minute in a new cell.

我是Excel VBA的新手。我想设置一个循环,显示新单元格中每分钟的时间。

Is there a way to display only the time (hh:mm:ss) in a cell without seeing the date beside it? Also, I'd like the time zone shown. (e.g. Singapore Time, "SGT").

有没有办法在单元格中只显示时间(hh:mm:ss)而不会看到它旁边的日期?另外,我想要显示的时区。 (例如新加坡时间,“SGT”)。

Here is an example of the output I'd like to see:

以下是我想看到的输出示例:

23-Oct-13 10:00:00 AM SGT
23-Oct-13 10:01:00 AM SGT
23-Oct-13 10:02:00 AM SGT
23-Oct-13 10:03:00 AM SGT
23-Oct-13 10:04:00 AM SGT
23-Oct-13 10:05:00 AM SGT
23-Oct-13 10:06:00 AM SGT
23-Oct-13 10:07:00 AM SGT
23-Oct-13 10:08:00 AM SGT
23-Oct-13 10:09:00 AM SGT
23-Oct-13 10:10:00 AM SGT
23-Oct-13 10:11:00 AM SGT
23-Oct-13 10:12:00 AM SGT
23-Oct-13 10:13:00 AM SGT
23-Oct-13 10:14:00 AM SGT
23-Oct-13 10:15:00 AM SGT
23-Oct-13 10:16:00 AM SGT
23-Oct-13 10:17:00 AM SGT
23-Oct-13 10:18:00 AM SGT
23-Oct-13 10:19:00 AM SGT
23-Oct-13 10:20:00 AM SGT
...

3 个解决方案

#1


4  

This Should do it, have Fun. :-)

这应该做到,玩得开心。 :-)

Option Explicit
Sub test()
    Dim i&, sTime As Date, TimeStep As Date, Cell As Range
    '// Format range cell to 24Hrs
    With Range("A1:A1440") '// 24H*60M
        .NumberFormat = "HH:MM:SS;@"
    End With

    Set Cell = [A1] '// first cell to write
        sTime = "00:00:00"  '// start time
    '// Loop 24hrs
    TimeStep = "00:01:00" '// time increment
    For i = 0 To 1439 ' // 1439 means 1439 cells
        Cell.Offset(i, 0).Value = sTime
        sTime = sTime + TimeStep
    Next i
End Sub

Start

enter image description here

End

enter image description here

#2


3  

ok, now that you explained a bit in more depth,

好的,既然你有更深入的解释,

ActiveSheet.Cells(1, 1).Value = "00:00:00"
ActiveSheet.Cells(2, 1).Value = "00:01:00"
Range("A1:A2").Select
Selection.AutoFill Destination:=Range("A1:A1440"), Type:=xlFillDefault

should do the trick

应该做的伎俩

#3


0  

To retrieve time format you can use:

要检索时间格式,您可以使用:

=Mid(A1,11,8)*1 into function bar (with additional column)

or into a sub

或者成子

timeOnClock= Mid(MyString, 10, 9)*1

then for your first row (23-Oct-13 10:00:00 AM SGT) you retrieve 0,416666667 and you can choice your prefer format

那么你的第一行(23-Oct-13 10:00:00 SGT)你检索0,416666667,你可以选择你喜欢的格式


推荐阅读
author-avatar
佳蓁政睿9
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有