将Excel中的时间从24小时制转换为12小时制

huangapple go评论151阅读模式
英文:

Converting Excel values from 24h to 12h

问题

我有一系列需要转换的时间,目前它们在两列(J和K)中,我需要它们放在一个单独的列中,以12小时制显示。

例如:

列 J 列 K
1403 1430
855 1000

我需要它们的格式如下:

列 J 列 K 列 L
1403 1430 02:03 PM - 02:30 PM
855 1000 08:55 AM - 10:00 AM

我尝试了十几种不同的方法,但我最多只能将这些列转换为各种12:00 AM的变体。

英文:

I have a series of times I need to convert, currently they're in two columns (J & K) and I need them to be in a single column, as 12 hour times

eg:

Column J Column K
1403 1430
855 1000

And I need them in the format of

Column J Column K Column L
1403 1430 02:03 PM - 02:30 PM
855 1000 08:55 AM - 10:00 AM

I've tried a dozen different methods and the best I can do is convert the columns just to variations of 12am

答案1

得分: 0

在单元格L2中使用以下公式,并根据需要复制:

=TEXT(TIME(LEFT(J2,LEN(J2)-2),RIGHT(J2,2),0),"hh:mm AM/PM") & " - " & TEXT(TIME(LEFT(K2,LEN(K2)-2),RIGHT(K2,2),0),"hh:mm AM/PM")

请注意:尽管这看起来很漂亮,但实际上使时间更难处理,因为现在它以文本形式存储。每当需要处理时间时,您将需要从文本中提取时间。我建议将时间存储为数字,使用三列,并对时间列应用自定义格式。以下是一个示例:

英文:

Use the following formula in cell L2 and copy down as required:

=TEXT(TIME(LEFT(J2,LEN(J2)-2),RIGHT(J2,2),0),"hh:mm AM/PM") & " - " &TEXT(TIME(LEFT(K2,LEN(K2)-2),RIGHT(K2,2),0),"hh:mm AM/PM")

将Excel中的时间从24小时制转换为12小时制

NOTE: While this may look pretty it actually makes the time harder to work with since its now stored as text. You will need to strip the time from the text any time you need to work with it. I would recommend storing the time as a number, using three columns, and applying a custom format to the time column. Below is an example:

将Excel中的时间从24小时制转换为12小时制

答案2

得分: 0

An alternative approach using TEXT( ) Function.


• Formula used in cell L2

=TEXT(
TEXT(J2, "00:00"),
"hh:mm AM/PM"
) & " - " &
TEXT(
TEXT(K2, "00:00"),
"hh:mm AM/PM"
)


Or, Using TEXTJOIN( )


• Formula used in cell L2

=TEXTJOIN(
" - ",
,
TEXT(
TEXT(J2:K2, "00:00"),
"hh:mm AM/PM"
)
)


英文:

An alternative approach using <kbd>TEXT( )</kbd> Function.

将Excel中的时间从24小时制转换为12小时制


• Formula used in cell <kbd>L2</kbd>

=TEXT(
    TEXT(J2, &quot;00\:00&quot;),
    &quot;hh:mm AM/PM&quot;
) &amp; &quot; - &quot; &amp;
    TEXT(
        TEXT(K2, &quot;00\:00&quot;),
        &quot;hh:mm AM/PM&quot;
    )

Or, Using <kbd>TEXTJOIN( )</kbd>

将Excel中的时间从24小时制转换为12小时制


• Formula used in cell <kbd>L2</kbd>

=TEXTJOIN(
    &quot; - &quot;,
    ,
    TEXT(
        TEXT(J2:K2, &quot;00\:00&quot;),
        &quot;hh:mm AM/PM&quot;
    )
)

huangapple
  • 本文由 发表于 2023年7月18日 08:41:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76708873.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定