- Home /
Convert this string formatting from C# to JS
I want to convert this C# code to JS:
myTimer -= Time.deltaTime;
int minutes = Mathf.FloorToInt(myTimer / 60F);
int seconds = Mathf.FloorToInt(myTimer - minutes * 60);
string niceTime = string.Format("{0:0}:{1:00}", minutes, seconds);
myLabel.text= niceTime;
Here is what I have so far:
myTimer -= Time.deltaTime; // Count down the time in seconds on timer
var minutes :int = Mathf.FloorToInt(myTimer / 60F);
var seconds :int = Mathf.FloorToInt(myTimer - minutes * 60);
string niceTime = string.Format("{0:0}:{1:00}", minutes, seconds);
I am stuck on the string formatting part, how do I write this in JS?
You should ask this on StackOverflow, this isn't Unity related.
@teuchito - actually in a twisted sort of way this is Unity related. Javascript/Unityscript is specific to Unity, so only someone with Unity experience could give him a definitive answer.
Answer by robertbu · Apr 30, 2014 at 01:47 AM
As with other variables, niceTime needs to be declared with 'var'. And for some unknown reason (to me), the string class is access in Javascript with an upper case 'S'. Functionality is the same since it is .NET.
var niceTime = String.Format("{0:0}:{1:00}", minutes, seconds);
Your answer
Follow this Question
Related Questions
this script in Javascript?? 0 Answers
help with creating a static Instance in javascript 2 Answers
Multiple Cars not working 1 Answer
How to make this line work in C#? 1 Answer
Small translation issue 1 Answer