Results 1 to 9 of 9

Thread: Convert hour from 24h to 12h AM/PM format

  1. #1
    Raw Wave pierrotm777's Avatar
    Join Date
    May 2008
    Location
    Bordeaux, France
    Posts
    2,840

    Convert hour from 24h to 12h AM/PM format

    Hello, need some help please !

    This is my code:
    Code:
        Public Function UsTime(ByVal Value As String) As String
            UsTime = ""
            If TempPluginSettings.X10AMPMHour = False Then
                UsTime = Value
            Else
                UsTime = Format(CType(Value, Date), "h:mm tt")
            End If
            Return UsTime
        End Function
    I use the code as:
    Myval = UsTime("00:01")

    I try to convert a hour from 24h to 12h:
    ex:24h > 00:01 --> 12h 00:01 AM

    My problem is that return me 12:01 AM and not 00:01 AM

    Where is my issue please ?

  2. #2
    Variable Bitrate
    Join Date
    Sep 2012
    Location
    Germany - Munich
    Posts
    378
    i think it is correct.

    24h 00:01 = 12:01 AM

    http://www.wikihow.com/Convert-from-...o-12-Hour-Time
    Last edited by harryberlin; 02-26-2014 at 02:23 PM.

  3. #3
    Confusion Master
    Auto Apps:loading...
    Enforcer's Avatar
    Join Date
    Sep 2003
    Location
    If you go down to the woods today, You're sure of
    Posts
    14,625

  4. #4
    Variable Bitrate
    Join Date
    Sep 2012
    Location
    Germany - Munich
    Posts
    378
    Did a short test in excel with this:

    A1 has 24h
    A2 gets 12h incl. AM PM string

    Code:
    Cells(2, 1) = Format(Cells(1, 1), "hh:mm AMPM") & IIf(Format(Cells(1, 1), "hh") >= 12, "PM", "AM")
    i know, it's bad code.
    Last edited by harryberlin; 02-26-2014 at 03:07 PM.

  5. #5
    Raw Wave
    Join Date
    Nov 2009
    Posts
    2,119
    There is no 0 (zero) hour in AM/PM format; it exists only in 24 hour format.

  6. #6
    Raw Wave pierrotm777's Avatar
    Join Date
    May 2008
    Location
    Bordeaux, France
    Posts
    2,840
    Quote Originally Posted by harryberlin View Post
    i think it is correct.

    24h 00:01 = 12:01 AM

    http://www.wikihow.com/Convert-from-...o-12-Hour-Time
    If i understand well:
    24h 00:01 --> 12h 00:01 AM
    24h 12:01 --> 12h 00:01 PM

    Exact ?

  7. #7
    Raw Wave
    Join Date
    Nov 2009
    Posts
    2,119
    No.

    24h 00:01 --> 12h 12:01 AM
    24h 12:01 --> 12h 12:01 PM

  8. #8
    Raw Wave pierrotm777's Avatar
    Join Date
    May 2008
    Location
    Bordeaux, France
    Posts
    2,840
    I understand now , thanks:

    Code:
       '12 heures 	12 am 	1 am 	2 am 	3 am 	4 am 	5 am 	6 am 	7 am 	8 am 	9 am 	10 am 	11 am 	12 pm 	1 pm 	2 pm 	3 pm 	4 pm 	5 pm 	6 pm 	7 pm 	8 pm 	9 pm 	10 pm 	11 pm
        '24 heures 	0 h 	1 h 	2 h 	3 h 	4 h 	5 h 	6 h 	7 h 	8 h 	9 h 	10 h 	11 h 	12 h 	13 h 	14 h 	15 h 	16 h 	17 h 	18 h 	19h 	20 h 	21 h 	22 h 	23 h

  9. #9
    Raw Wave pierrotm777's Avatar
    Join Date
    May 2008
    Location
    Bordeaux, France
    Posts
    2,840
    For info , i have found a good method, use the CultureInfo Class!

    First , select a Culture:
    Code:
        Public Sub SelectNewCulture(ByVal index As String) 'index = English or French
            Select Case index
                Case "English" : NewCulture = New CultureInfo("en-US", False)
                Case "French" : NewCulture = New CultureInfo("fr-FR", False)
            End Select
            Thread.CurrentThread.CurrentCulture = NewCulture
            Thread.CurrentThread.CurrentUICulture = NewCulture
    
        End Sub
    Secondly:
    Code:
        Public Function UsTime(ByVal Value As String) As String
            UsTime = ""
    
            If Value = "DAWN" Or Value = "DUSK" Then
                UsTime = Value
            Else
                If TempPluginSettings.X10AMPMHour = False Then
                    UsTime = Value
                Else
                    UsTime = Convert.ToDateTime(Value).ToString("hh:mm tt", NewCulture)
                End If
            End If
            Return UsTime
        End Function

Similar Threads

  1. 24 hour time possible?
    By drakino in forum StreetDeck
    Replies: 0
    Last Post: 07-25-2007, 12:10 AM
  2. $1 Million An Hour...
    By W3bMa5t3r in forum Off Topic
    Replies: 10
    Last Post: 10-07-2006, 11:36 PM
  3. 24 hour firesale
    By greenman100 in forum Classified Archive
    Replies: 38
    Last Post: 05-21-2006, 05:04 PM
  4. IC 555 to pulse 1 hour?
    By phita23 in forum Newbie
    Replies: 9
    Last Post: 02-20-2005, 01:48 AM
  5. hour meter
    By albysure in forum Software & Software Development
    Replies: 4
    Last Post: 06-10-2003, 11:45 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •