# Can "return" be applied to a String?

**URL:** <https://discourse.processing.org/t/can-return-be-applied-to-a-string/10823>\
**Category:** Beginners\
**Created:** [May 1, 2019, 11:13pm UTC](https://discourse.processing.org/t/can-return-be-applied-to-a-string/10823 "2019-05-01T23:13:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![laptophead](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/laptophead/32/2701_2.png) [@laptophead](https://discourse.processing.org/u/laptophead)\
**Post date:** [May 1, 2019, 11:13pm UTC](https://discourse.processing.org/t/can-return-be-applied-to-a-string/10823/1 "2019-05-01T23:13:23Z")

</div>

I wrote this little function to convert miliseconds to Human readible time.

I would like to use “return” to make life simple.

So I tried:

```auto
 void MsConversion(int MS)

{
int totalSec= (MS / 1000);
int seconds = (MS / 1000) % 60;
int minutes = (MS / (1000*60)) % 60;
int hours = ((MS/(1000*60*60)) % 24);                      
 HumanTime= (hours+":" +nf(minutes, 2, 0)+ ":"+ nf(seconds, 2, 0));
return HumanTime;

//println (HumanTime);
}

```

but I get:

Void methods cannot return a value

Finally, I would want to use this function like this:

String ReadHere = MsConversion (8998798798);

and obtain a nice 8:44:43 for the string.

Is it possible?  
Thanks

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [May 2, 2019, 12:28am UTC](https://discourse.processing.org/t/can-return-be-applied-to-a-string/10823/2 "2019-05-02T00:28:13Z")

</div>

If you want to return a value from a function, you have to give your function a return type. In your case it would probably look like this:

```java
String MsConversion(int MS) {
  // ...

```

---

<div class="post-metadata">

**Author:** ![hotfooted](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hotfooted/32/3670_2.png) [@hotfooted](https://discourse.processing.org/u/hotfooted)\
**Post date:** [May 2, 2019, 12:28am UTC](https://discourse.processing.org/t/can-return-be-applied-to-a-string/10823/3 "2019-05-02T00:28:44Z")

</div>

you just need to set the return type of the method

void returns nothing but you can replace it with just about any other type so replace void with String and your method will work

```auto
String MsConversion(int MS)
{
   int totalSec= (MS / 1000);
   int seconds = (MS / 1000) % 60;
   int minutes = (MS / (1000*60)) % 60;
   int hours = ((MS/(1000*60*60)) % 24);                      
   
   HumanTime= (hours+":" +nf(minutes, 2, 0)+ ":"+ nf(seconds, 2, 0));
   
   return HumanTime;
   //println (HumanTime);
}

```

---

<div class="post-metadata">

**Author:** ![laptophead](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/laptophead/32/2701_2.png) [@laptophead](https://discourse.processing.org/u/laptophead)\
**Post date:** [May 2, 2019, 12:08pm UTC](https://discourse.processing.org/t/can-return-be-applied-to-a-string/10823/4 "2019-05-02T12:08:43Z")

</div>

Thanks , that was easy

Mitch
