question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

how can I set Date format

See original GitHub issue

I have already read source

if (locals.config.format) { formattedValue = locals.config.format(locals.value); }

but my function need pass two arguments, for example:formatDate(“yyyy-mm-d h:f:s”,“Tue Jul 5 2016 10:04:52 GMT+0800 (中国标准时间)”), because my form is dynamically generated, every date format is different。 how can I do it?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

14reactions
jariwalabhaveshcommented, Jan 17, 2017

@alvaromb Thanks for reply, after you reply i again tested code and it start working, i didn’t know what was actual reason. But now it is working and HERE IS WORKING EXAMPLE

class DateComponent extends Component {
    constructor(props) {
        super(props);
        this.state = {
        }
    }

    render() {
        var Person = t.struct({
            effectiveDate: t.Date // a date field
        });
        let myFormatFunction = (format,date) =>{
            return moment(date).format(format);
        }
        var effectiveDate = {
            label: 'Effective Date',
            mode:'date',
            config:{
                format:(date) => myFormatFunction("DD MMM YYYY",date)
            }
        };
        let options = {
            fields: {
               "effectiveDate":effectiveDate
            }
        };
        return (
            <View style={styles.container}>
                <View>
                    <Form ref="documentDate" type={Person} value={this.state.dateValue} options={options} />
                </View>
            </View>
        );
    }
}

I had used momentjs for formating date I will be glad if this example helps someone Thanks very much @alvaromb

2reactions
gcanticommented, Jul 6, 2016

Currying?

const myFormatFunction = format => date => formatDate(format, date)
const myFormat1 = 'yyyy-mm-d h:f:s'
const myFormat2 = 'yyyy-mm-d'
// etc...

...

const formOptions = {
  fields: {
    myDate: {
      config: {
        format: myFormatFunction(myFormat1)
      }
    }
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Change Date and Time Format in Windows 10
How to Change Date and Time Formats in Settings · Open settings. Press the Start button, then click the settings cog, above the...
Read more >
How to Change the Date and Time Format in Windows
To change the date format, click on Short date and Long date drop-down menus to display the list of available options. Choose any...
Read more >
How to Change the Date and Time Format on Windows
Right-click the time and date in the bottom-right corner of the taskbar and select Adjust date and time. · Scroll down and select...
Read more >
How to change Excel date format and create custom ...
Select the cell with a date in Excel, press Ctrl+1 to open the Format Cells window and switch to the General tab. If...
Read more >
How to change date and time formats on Windows 10
Under format click the Change date and time formats link. · Use the Short name drop-down menu to select the date format you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found