DateTime
Ooh, its very complicated.... I think perhaps either it isn't finished or else someone is veering away from the concept of BASIC being a high level language.
You might as well just give us inline assembler and we'll program it ourselves in assembly language
Please regard this post as constructive criticism and note that Erel himself has remarked that he sometimes is not aware of difficulties that new users may encounter as attested to by this thread:
http://www.b4x.com/forum/basic4andr...ls/9049-collecting-tips-beginners-wanted.html
The thing I like about BASIC and B4a especially is that I can hold it in my head and that makes it a joy to use.
Now I get the idea with 'ticks' and these are represented in a Long variable, ok so (you don't give us any examples but...) a typical example of this long variable number would be the date and time of writing this text which is:
12:49pm on Sunday the 20th of January 2013
(by the way, if you want to represent a date and time like that be prepared for some serious programming)
So the tick value for the above date and time, heck let's begin to call it DateTime is: 1358686183885
There, that wasn't so hard to give an example now was it?
So here's a quick 'lightning quiz' for you. Using the very friendly B4a BASIC language take that long integer '1358686183885' and turn it back into the format as above:
12:49pm on Sunday the 20th of January 2013
Shouldn't be so hard right? I'm sure BASIC has some nice easy useful functions to do it right?
So then, if you're a mathmatician you can add and subtract numbers to that long integer and if you do
DateTime.Now and get a number like the example above then that big long number represents milliseconds since the 1st of January 1970
(one presumes that was Erel's birthdate ) hehe.
But we are given some rather low-level functions to manipulate these massive numbers so that's great then but not very friendly.
Awwww, does ianyweany want some little fluffy basic pink boxes with easy functions cozy nestled inside?
Well Yes, he does then he can hold them in his head without having to re-learn everything about DateTime each and every time he needs to use it!
Look what I have to do to get the name of the day or the name of the month
lblMyLabel.Text = "Hello today it is " & .... erm ... oh I give up but I need it, search the forum, nope, search the wiki, nope, where is that code I wrote a couple of months ago... oh here it is...
Dim dayName("noDay", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday") as String
Dim monthName("noMonth", "January", "February", "March" ... oh you know where I'm going with this.
Actually I did find the answer to naming the days of the week on the forum from some other poor soul who was under the same kind of torture Here:
http://www.b4x.com/forum/basic4android-updates-questions/15104-getdayofmonth.html#post85683
So now it would seem that if I do:
lblMyLabel.Text = "Hello today it is " & dayName(GetDayOfWeek(1358686183885))
Then that might supply me with something friendly like "Hello today it is Sunday"
But it might not! because some people might not have their days of the week set the same as me, because although you would have
thought that everyone starts work on a Monday and therefore Monday is the first day of the week, it would seem that some people start work on a Sunday..... go figure
Perhaps the pope does? Sunday being religious and all? Therefore we obviously need a new BASIC function If NOT Pope Then .... hehe
So, I may or may not have a reliable way of getting the name of the day of the week and if not then my app will just look silly telling someone it's Monday when its Sunday but ok.
A nice useful BASIC function enabling me not to have to re-learn everything about DateTime each time I use it might have been:
lblMyLabel.Text=DateTime.dayName(1358686183885)
Another one might be:
lblMyLabel.Text=DateTime.monthName(1358686183885)
I'll bet these are already in there somewhere and can probably be got at using the reflector library so the above functions might only need to be wrappers and hopefully fairly easy to implement?
Perhaps some other useful BASIC functions might be:
text = DateTime.daySuffix(1358686183885) ' Returns either 'st', 'rd', 'nd' or 'th' then you can do 'Saturday the 24th of February' or 'Friday the 2nd of January' or 'Thursday the 3rd of March' etc.
I know it is fairly easy to program, if the number ends with 2 its nd if it ends with 3 then its rd, if it ends with 1 its st and everything else is th (i think) but it could be a handy function then we wouldn't have to dig out that old code each time or in other words, we could hold it in our heads.
See BASIC! Easy to remember, friendly.
DateTime.ampmTime might serve up the DateTime's time element as a string such as: 12:49pm or 0:49am and DateTime.longDate would return a string like Sunday the 20th of January thus to get the string as I wrote it at the top of this post would be:
lblMyLabel.Text = DateTime.ampmTime(wroteDT) & " on " & DateTime.longDate(wroteDT) & " " & DateTime.GetYear(wroteDT)
or perhaps just lblMyLabel.Text = DateTime.longDate2(wroteDT)
which either way would come out as =:
12:49pm on Sunday the 20th of January 2013
Phew!
Ooh, its very complicated.... I think perhaps either it isn't finished or else someone is veering away from the concept of BASIC being a high level language.
You might as well just give us inline assembler and we'll program it ourselves in assembly language
Please regard this post as constructive criticism and note that Erel himself has remarked that he sometimes is not aware of difficulties that new users may encounter as attested to by this thread:
http://www.b4x.com/forum/basic4andr...ls/9049-collecting-tips-beginners-wanted.html
The thing I like about BASIC and B4a especially is that I can hold it in my head and that makes it a joy to use.
Now I get the idea with 'ticks' and these are represented in a Long variable, ok so (you don't give us any examples but...) a typical example of this long variable number would be the date and time of writing this text which is:
12:49pm on Sunday the 20th of January 2013
(by the way, if you want to represent a date and time like that be prepared for some serious programming)
So the tick value for the above date and time, heck let's begin to call it DateTime is: 1358686183885
There, that wasn't so hard to give an example now was it?
So here's a quick 'lightning quiz' for you. Using the very friendly B4a BASIC language take that long integer '1358686183885' and turn it back into the format as above:
12:49pm on Sunday the 20th of January 2013
Shouldn't be so hard right? I'm sure BASIC has some nice easy useful functions to do it right?
So then, if you're a mathmatician you can add and subtract numbers to that long integer and if you do
DateTime.Now and get a number like the example above then that big long number represents milliseconds since the 1st of January 1970
(one presumes that was Erel's birthdate ) hehe.
But we are given some rather low-level functions to manipulate these massive numbers so that's great then but not very friendly.
Awwww, does ianyweany want some little fluffy basic pink boxes with easy functions cozy nestled inside?
Well Yes, he does then he can hold them in his head without having to re-learn everything about DateTime each and every time he needs to use it!
Look what I have to do to get the name of the day or the name of the month
lblMyLabel.Text = "Hello today it is " & .... erm ... oh I give up but I need it, search the forum, nope, search the wiki, nope, where is that code I wrote a couple of months ago... oh here it is...
Dim dayName("noDay", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday") as String
Dim monthName("noMonth", "January", "February", "March" ... oh you know where I'm going with this.
Actually I did find the answer to naming the days of the week on the forum from some other poor soul who was under the same kind of torture Here:
http://www.b4x.com/forum/basic4android-updates-questions/15104-getdayofmonth.html#post85683
So now it would seem that if I do:
lblMyLabel.Text = "Hello today it is " & dayName(GetDayOfWeek(1358686183885))
Then that might supply me with something friendly like "Hello today it is Sunday"
But it might not! because some people might not have their days of the week set the same as me, because although you would have
thought that everyone starts work on a Monday and therefore Monday is the first day of the week, it would seem that some people start work on a Sunday..... go figure
Perhaps the pope does? Sunday being religious and all? Therefore we obviously need a new BASIC function If NOT Pope Then .... hehe
So, I may or may not have a reliable way of getting the name of the day of the week and if not then my app will just look silly telling someone it's Monday when its Sunday but ok.
A nice useful BASIC function enabling me not to have to re-learn everything about DateTime each time I use it might have been:
lblMyLabel.Text=DateTime.dayName(1358686183885)
Another one might be:
lblMyLabel.Text=DateTime.monthName(1358686183885)
I'll bet these are already in there somewhere and can probably be got at using the reflector library so the above functions might only need to be wrappers and hopefully fairly easy to implement?
Perhaps some other useful BASIC functions might be:
text = DateTime.daySuffix(1358686183885) ' Returns either 'st', 'rd', 'nd' or 'th' then you can do 'Saturday the 24th of February' or 'Friday the 2nd of January' or 'Thursday the 3rd of March' etc.
I know it is fairly easy to program, if the number ends with 2 its nd if it ends with 3 then its rd, if it ends with 1 its st and everything else is th (i think) but it could be a handy function then we wouldn't have to dig out that old code each time or in other words, we could hold it in our heads.
See BASIC! Easy to remember, friendly.
B4X:
Dim wroteDT as long = 1358686183885
lblMyLabel.Text="Because I wrote this text at " & _
DateTime.ampmTime(wroteDT) & " on " & DateTime.dayName(wroteDT) & _
" the " & DateTime.GetDayOfMonth(wroteDT) & _
DateTime.daySuffix(wroteDT) " of " & _
DateTime.monthName(wroteDT) & " " & _
DateTime.GetYear(wroteDT) & _
" my fingers are knackered because of all that typing. It would have been a whole lot easier," & _
" although these functions would come in handy to split up the various elements of a DateTime string " & _
"yet what about if I just told you that I wrote this text at " & _
DateTime.ampmTime(wroteDT) & " on " & DateTime.longDate(wroteDT) & _
" " & DateTime.GetYear(wroteDT) & " ?"
lblMyLabel.Text = DateTime.ampmTime(wroteDT) & " on " & DateTime.longDate(wroteDT) & " " & DateTime.GetYear(wroteDT)
or perhaps just lblMyLabel.Text = DateTime.longDate2(wroteDT)
which either way would come out as =:
12:49pm on Sunday the 20th of January 2013
Phew!
Last edited: