Blue Theme Orange Theme Green Theme Red Theme
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Home | Forums | ASP.NET 2.0 Tutorials | Web Services | How Do I...? | Class Browser | WPF Quick Starts | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
Search :       Advanced Search »
Home » Blogs Home » Blog Detail

How to convert seconds to hh:mm:ss format in csharp

 by Satyapriya Nayak on Jan 12, 2012

In this blog we will know how to convert seconds to hh:mm:ss format in csharp.
Download Files: Convert seconds to Hour Minute Second.rar
Comments: 0 Views: 674 Printable Version 

In this blog we will know how to convert seconds to hh:mm:ss format in csharp.

 

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

 

namespace WindowsFormsApplication1

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void Form1_Load(object sender, EventArgs e)

        {

            MessageBox.Show(ConvertToTime(90640));

        }

        public string ConvertToTime(double timeSeconds)

        {

            int mySeconds = System.Convert.ToInt32(timeSeconds);

 

            int myHours = mySeconds / 3600; //3600 Seconds in 1 hour

            mySeconds %= 3600;

 

            int myMinutes = mySeconds / 60; //60 Seconds in a minute

            mySeconds %= 60;

 

 

            string mySec = mySeconds.ToString(),

            myMin = myMinutes.ToString(),

            myHou = myHours.ToString();

 

            if (myHours < 10) { myHou = myHou.Insert(0, "0"); }

            if (myMinutes < 10) { myMin = myMin.Insert(0, "0"); }

            if (mySeconds < 10) { mySec = mySec.Insert(0, "0"); }

 

 

            return myHou + "hh"+":" + myMin + "mm"+":" + mySec +"ss";

        }

    }

}

 

 

Output

 

25hh:10mm:40ss

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
 
What do you say about this post? Post a comment here
*Title:
*Comment:
 
Comments not available.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor

 Blogger's Profile
Age: Not Available
Location:
Title: Student
Joined: Aug 02, 2010
Education: Bachelors Degree
 More Blogs from this Blogger
No record available
 Latest Blogs
[Video] OnClose Handler
[Video] Storing and Loading the Window and Toolbar position
The Euclidean Algorithm
Swapping Exe Process
How Exe file is Generated by VS2005 C++ Project?
What is Exe
Header files: Multiple Inclusion problem - Solution B
Header files: Multiple Inclusion problem - Solution A
Header files: Multiple Inclusion problem - Reason
Header files: Multiple Inclusion problem
View all »
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 
Team Foundation Server Hosting
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.