Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    May 2009
    Posts
    158
    Thanks
    71
    Thanked 1 Time in 1 Post

    ammending variable

    Hi guys, just having a bit of a problem ammending a variable. Say I have a variable called dateString, which holds a String of any date in the form of
    23 SEPTEMBER 2013 (SUN)
    So basically dateString can be any date in the above form. Say I wanted to change it so the date takes the form of
    23/09/2013
    Would something like this be possible? I have removed the spaces like so
    dateString.replace(/ /g,'');
    How would I go about doing the rest?

    Thanks

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,065
    Thanks
    36
    Thanked 497 Times in 491 Posts

    Lightbulb

    Sort of an unusual date format, but you might just write a function to convert it like...
    Code:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8" />
    <title> Untitled </title>
    
    </head>
    <body>
    
    <script type="text/javascript">
    var originalStr = '23 SEPTEMBER 2013 (SUN)';
    var newString = converDateString(originalStr);
    alert(newString);
    
    function converDateString(info) {
      var Months = '   JanFebMarAprMayJunJulAugSepOctNovDec'.toUpperCase();
      var tarr = info.split(' ');
      var m = Math.floor(Months.indexOf(tarr[1].substr(0,3)) / 3);
      if (m < 10) { m = '0'+m; }
      return tarr[0]+'/'+m+'/'+tarr[2];
    }
    
    </script>
    
    </body>
    </html>

  • Users who have thanked jmrker for this post:

    nick2price (04-14-2013)

  • #3
    Regular Coder
    Join Date
    May 2009
    Posts
    158
    Thanks
    71
    Thanked 1 Time in 1 Post
    Thanks for the fantastic advice. I forgot one thing, the String I have is a dynamic variable, and it also comes with its table layout
    Code:
    <table><tbody><tr><td class="day-align">2</td><td class="month-align">FEBRUARY</td><td class="year-align">2013</td><td class="weekday-align">(SAT)</td></tr></tbody></table>
    Is there any way to remove this too?

    Thanks

  • #4
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,065
    Thanks
    36
    Thanked 497 Times in 491 Posts

    Exclamation

    Quote Originally Posted by nick2price View Post
    Thanks for the fantastic advice. I forgot one thing, the String I have is a dynamic variable, and it also comes with its table layout
    Code:
    <table><tbody><tr><td class="day-align">2</td><td class="month-align">FEBRUARY</td><td class="year-align">2013</td><td class="weekday-align">(SAT)</td></tr></tbody></table>
    Is there any way to remove this too?

    Thanks
    That's a significant part to forget!

    Are you trying to remove three <td>...</td> elements and replace it with one?

    If I were you, I would change the dynamic generation part to write the table
    in the correct format you desire in the first place rather than try to modify
    it with a bunch of kludge code.

  • #5
    Regular Coder
    Join Date
    May 2009
    Posts
    158
    Thanks
    71
    Thanked 1 Time in 1 Post
    Unfortunately its not as easy as just removing it. I am working in JQuery Mobile, and this is for a specific list display. For this list, I essentially do
    Code:
    $.each(days, function (i, item) {
                var currentDate = new Date(year, month-1, item);
                var returnValue = "<table><tr><td class='day-align'>"+currentDate.getDate()+"</td>";
                returnValue += "<td class='month-align'>"+ monthString[currentDate.getMonth()]+"</td>";
                returnValue += "<td class='year-align'>"+currentDate.getFullYear()+"</td>";
                returnValue += "<td class='weekday-align'>"+"("+weekday[currentDate.getDay()]+")"+"</td></tr></table>";
                var $li = $("<li/>").addClass("ui-li ui-li-static ui-btn-up-c comp-align").html(returnValue).appendTo($list);
    
                $li.on("tap", onItemTap);
            });
    Code:
    var onItemTap = function () {
                var value = $(this).html();
                onchoice(value);
            }
    I need the table to align things neatly, because it would be a difficult job with just css. Even if I used a span instead, it would still display in the tapped value.

    The above produces the layout I noted in the original post, which is how it needs to be for one list. For another list though, it needs the layout I am now attempting to achieve. It would probably be easiest to remove anything to do with tables for this new list, and just have it as a simple string.

  • #6
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,065
    Thanks
    36
    Thanked 497 Times in 491 Posts
    I don't use JQuery, so I'd be of little help here.

    You might try posting to the other sub-section of this forum, "Javascript frameworks".
    Located near the top of the page on the site leading to this thread.
    See: http://www.codingforums.com/javascript-frameworks/

  • Users who have thanked jmrker for this post:

    nick2price (04-14-2013)


  •  

    Posting Permissions

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