Any library is not present but function has been made.Is there a lib that will easily convert "2013-02-05" to "Tuesday, February 5, 2013" and "15:30:00" to "3:30 PM"? Thanks.
Dim now As Long
now = DateTime.now
DateTime.DateFormat = "EEEE, MMMM d, yyy"
Msgbox(DateTime.Date(now),"")
DateTime.DateFormat = "hh:mm a"
Msgbox(DateTime.Date(now),"")
Sub dayName(dt As Long) As String
Dim dayNames() As String:dayNames = Array As String("","Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
Return dayNames(DateTime.GetDayOfWeek(dt))
End Sub
Sub monthName(dt As Long) As String
Dim monthNames() As String:monthNames = Array As String("", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
Return monthNames(DateTime.GetMonth(dt))
End Sub
Sub ampmTime(dt As Long) As String
Dim h As Int
Dim i As Double
i = DateTime.GetMinute(dt)
h = DateTime.GetHour(dt)
If h <= 11 Then
If h = 0 Then h = 12 'coz we can't have hours as zero :)
Return h & ":" & NumberFormat(i, 2, 0) & "am"
End If
h = h - 12
If h = 0 Then h = 12 'coz we can't have hours as zero :)
Return h & ":" & NumberFormat(i, 2, 0) & "pm"
End Sub
Sub daySuffix(i As Int) As String 'add suffix to integer such as 10th 3rd 1st 2022nd etc.
Dim s As String
Dim j As Int
s = i 'change the int to a string
j = i 'make a copy of i that we can chop up
If s.Length > 2 Then s = s.SubString(s.Length - 2)
j = s 'j is now a number that is no bigger than 2 digits
If j >= 4 AND j <= 20 Then Return i & "th" 'these last few
If s.EndsWith("1") Then Return i & "st" 'lines work out
If s.EndsWith("2") Then Return i & "nd" 'the correct suffix
If s.EndsWith("3") Then Return i & "rd" 'and send back the
Return i & "th" 'original number as a string with the correct suffix after it.
End Sub
Sub longDate(dt As Long) As String
Return dayName(dt) & " " & daySuffix(DateTime.GetDayOfMonth(dt)) & " of " & monthName(dt) & ", " & DateTime.GetYear(dt)
End Sub
Sub ampmTimeAndlongDate(dt As Long) As String
Return ampmTime(dt) & " on " & longDate(dt)
End Sub
To work with current date u can use this ..
B4X:Dim now As Long now = DateTime.now DateTime.DateFormat = "EEEE, MMMM d, yyy" Msgbox(DateTime.Date(now),"") DateTime.DateFormat = "hh:mm a" Msgbox(DateTime.Date(now),"")
for formatting parameters see here ...
Date Formatting
Cheers mj
DateTime.DateFormat = "yyyy-MM-dd"
chkstr = DateTime.GetDayOfWeek(DateTime.DateParse("2013-02-06"))
DateTime.DateFormat = "yyyy-MM-dd"
Dim chkstr As Int
Dim MyDays() As String
MyDays=Array As String("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
chkstr = DateTime.GetDayOfWeek(DateTime.DateParse("2013-02-06"))
Msgbox(MyDays(chkstr-1),"") 'will return Wednesday
Here's one way to do it:
B4X:DateTime.DateFormat = "yyyy-MM-dd" Dim t As Long = DateTime.DateParse("2013-02-06") DateTime.DateFormat = "EEEE" ' EEEE text day of week Dim chkstr As String = DateTime.Date(t)
DateTime.DateFormat = "yyyy-MM-dd"
Dim t As Long = DateTime.DateParse("2013-02-06")
DateTime.DateFormat = "EEEE, MMMM d, yyyy" ' EEEE text day of week
Dim chkstr As String = DateTime.Date(t)
DateTime.DateFormat = "yyyy-MM-dd HH:mm:ss"
Dim t As Long = DateTime.DateParse("2013-02-06 15:30:00")
DateTime.DateFormat = "EEEE, MMMM d, yyyy, h:mm aa" ' EEEE text day of week
Dim chkstr As String = DateTime.Date(t) ' chkstr = Wednesday, February 6, 2013, 3:30 PM
By the way, this is completely off-topic, but is there a way to copy code in forum posts to B4A so that the code retains formatting (CRLFs)?
Originally Posted by pixelpop View Post
By the way, this is completely off-topic, but is there a way to copy code in forum posts to B4A so that the code retains formatting (CRLFs)?
I know. It's a pain in the ass to copy and paste then go back and format the code. I've even tried copying it into Notepad++ and you still have to format it.
Are you just doing a highlight, Cntrl-C (or right mouse, Copy), then pasting into B4A? When I (and I assume others) do that, the copied lines of code are pasted with returns removed, resulting in one long line of code that has to be manually broken down into multiple lines again.
Again .. Off topic but
Slightly confused .. I frequently select/copy/past code directly into B4a without reformatting, maybe a tidy up (tabbing,indents etc.). Am I missing something ?
Cheers mj
Normally I highlight code and right click mouse to use context menu to copy and paste, but I just tried CTRL-C .. CTRL-V and the result was still good. ?
Win7 and Firefox.
Cheers mj