Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Time values in arraylist

Time values in arraylist

Scheduled Pinned Locked Moved C#
tutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 3981366
    wrote on last edited by
    #1

    Hi i want to have time in arraylist like following 9:45 AM 10:00 AM 10:15 AM 10:30 AM .... so basically 15 mins are added to previous item.. How to do this? Pls reply ASAP.

    H P 2 Replies Last reply
    0
    • M Member 3981366

      Hi i want to have time in arraylist like following 9:45 AM 10:00 AM 10:15 AM 10:30 AM .... so basically 15 mins are added to previous item.. How to do this? Pls reply ASAP.

      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #2

      Member 3981366 wrote:

      Pls reply ASAP.

      This is more likely to stop people from replying. Everybody here is a volunteer, if your problem is that urgent, then get your credit card out and go to rentacoder.com. Firstly, try not to use ArrayList, use List instead. It is type safe and more efficient. Look it up in the documentation for further details. Something like:

      		List timeList = new List();
      		DateTime startTime = new DateTime(1, 1, 1, 9, 0, 0);
      		DateTime endTime = new DateTime(1, 1, 1, 18, 0, 0);
      
      		while (startTime <= endTime)
      		{
      			timeList.Add(startTime);
      			startTime.AddMinutes(15);
      		}
      

      would work.

      Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

      P 1 Reply Last reply
      0
      • M Member 3981366

        Hi i want to have time in arraylist like following 9:45 AM 10:00 AM 10:15 AM 10:30 AM .... so basically 15 mins are added to previous item.. How to do this? Pls reply ASAP.

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        What will you do with it? Depending on what you plan to do, you may not actually need to store all that in memory. Here's an enumerator from my TimeRanger[^] article:

            public static System.Collections.Generic.IEnumerable<System.DateTime>
            MinuteEnumerator
            (
                System.DateTime StartPoint
            ,
                System.DateTime EndPoint
            ,
                ushort          SteppingFactor
            )
            {
                System.DateTime current = PIEBALD.Lib.LibTim.DateTruncate 
                ( 
                    StartPoint 
                , 
                    PIEBALD.Lib.LibTim.TimeGranularity.Minute 
                ) ;
                
                if ( StartPoint <= EndPoint )
                {
                    if ( current < StartPoint )
                    {
                        current = current.AddMinutes ( 1 ) ;
                    }
        
                    while ( current <= EndPoint )
                    {
                        yield return ( current ) ;
                        
                        current = current.AddMinutes ( SteppingFactor ) ;
                    }
                }
                else
                {
                    while ( current >= EndPoint )
                    {
                        yield return ( current ) ;
                        
                        current = current.AddMinutes ( SteppingFactor\*-1 ) ;
                    }
                }
                            
                yield break ;
            }
        

        Or you could use this to load a List if you really want to store the information.

        1 Reply Last reply
        0
        • H Henry Minute

          Member 3981366 wrote:

          Pls reply ASAP.

          This is more likely to stop people from replying. Everybody here is a volunteer, if your problem is that urgent, then get your credit card out and go to rentacoder.com. Firstly, try not to use ArrayList, use List instead. It is type safe and more efficient. Look it up in the documentation for further details. Something like:

          		List timeList = new List();
          		DateTime startTime = new DateTime(1, 1, 1, 9, 0, 0);
          		DateTime endTime = new DateTime(1, 1, 1, 18, 0, 0);
          
          		while (startTime <= endTime)
          		{
          			timeList.Add(startTime);
          			startTime.AddMinutes(15);
          		}
          

          would work.

          Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          To me, "ASAP" means the same as "when you can get around to it".

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups